Getting started code example
I. Initialize the system
The system can be initialized using common. inc. php in the root directory of the system.
For example, create a hello. php file in the root directory of the site.
Sample code:
The code is as follows: |
Copy code |
<? Php Require 'common. inc. Php '; Echo 'hello world '; ?> |
II. Write logic
After the system is initialized, you can write logic code in the PHP file and call the built-in variables, functions, and classes of the system.
Sample code:
The code is as follows: |
Copy code |
<? Php Require 'common. inc. Php '; Echo DT_ROOT; // physical path of the output site Echo '<br/> '; Echo DT_PATH; // the home address of the output site Echo '<br/> '; $ R = $ db-> get_one ("SELECT * FROM {$ DT_PRE} category"); // query a data entry FROM the category table Print_r ($ r); // Print the read data $ A = cache_read ('area. Php'); // read the regional cache of the system. Print_r ($ A); // Print the read data Print_r ($ MODULE); // Print System MODULE data Message ('Hello World'); // output a message ?> |
3. Application Template
All HTML output to the browser is displayed through the rules in the template.
Usage:
The code is as follows: |
Copy code |
Include template ('A', 'B '); |
Parameter a indicates the template name.
Parameter B indicates the directory where the template is stored. This parameter can be left unspecified.
If the template directory is default, then:
Template ('A', 'B'); represents the template/default/B/a.htm template file
Template ('A'); represents the template/default/a.htm template file
Sample code:
The code is as follows: |
Copy code |
<? Php Require 'common. inc. Php '; Template ('Hello '); ?> |
Template/default/hello.htm template file needs to be created in advance
After the system is initialized, the system automatically connects to the database and saves the database operation object in $ db. For database operation methods, see The include/db_mysql.class.php function prototype. The following is only an example of common operations.
1. Execute SQL statements
The code is as follows: |
Copy code |
$ Db-> query ("insert into '{$ DT_PRE} table' ('XXX') VALUES ('yyy ')"); $ Db-> query ("update' {$ DT_PRE} table 'set 'XXX' = 'yyy' WHERE 'zzz' = 1 ");
$ Db-> query ("delete from '{$ DT_PRE} table 'Where 'zzz' = 1 ");
|
2. Read multiple messages
The code is as follows: |
Copy code |
$ A = array (); $ Result = $ db-> query ("SELECT * FROM '{$ DT_PRE} table 'Where 'XXX' = 'yyy' order by 'zzz' desc limit "); While ($ r = $ db-> fetch_array ($ result )){ $ A [] = $ r; } Print_r ($ ); |
3. Read a single message
The code is as follows: |
Copy code |
$ A = $ db-> get_one ("SELECT * FROM '{$ DT_PRE} table 'Where 'XXX' = 'yyy '"); Print_r ($ ); |
4. Total number of computations
The code is as follows: |
Copy code |
$ A = $ db-> get_one ("select count (*) AS num FROM '{$ DT_PRE} table 'Where 'XXX' = 'yyy '"); Echo $ A ['num']; |
The system table prefix can use the variable $ DT_PRE (usually used in statements) or $ db-> pre (usually used in functions ).
If you use database operations in a function, you must first perform global $ db;
Category attribute filtering
Actual display effect:
The following uses the mall as an example to describe how to use it. Go to the mall management module to set the category attribute parameter to enable
Go to category management and click the number corresponding to the category attribute to be added
Add attributes (only the list selection and check box categories and the attributes used for search are displayed on the list and search pages)
After the attribute is added, the system automatically displays the option to fill in the attribute after the corresponding category is selected when the item is added.