ThinkPHP integrates the usage and query methods of the Smarty template engine. ThinkPHP integrates the usage and query methods of the Smarty template engine. In fact, we have nothing to do with integrating smarty, the main task is to use ThinkPHP to integrate the use of the Smarty template engine for template allocation of various variables and to summarize the query methods.
In fact, we have nothing to do to integrate smarty. The main thing to do is to use the template to allocate various variables. this is the focus, and some configuration information should be filled in by ourselves; let's talk about the configuration first. Similarly, you can write the configuration information into the config file under the common file in the main directory. the configuration information mainly includes the following configuration information.
'Tmpl _ ENGINE_TYPE '=> 'smarty ',
// 'Tmpl _ L_DELIM '=>' <{', // The standard tag of the template engine to start marking.
// 'Tmpl _ R_DELIM '=>'}> ', // tag end of a common tag of the template engine
// The above two configurations are not very good
// If a conflict occurs, use {literal} {/literal} to package it. This indicates that the template is not resolved.
You can use the above information to directly use the smarty template engine. for attention, the notes are described in.
Let's talk about the select method, which is generated for database queries. Simply using the select method is to retrieve all the data, but we do not need to waste this large resource in many cases. therefore, only by combining some query conditions can select be used better.
1: query field with fields:
$ T = D ('user ');
// $ Info = $ t-> select ();
$ Info = $ t-> field ("name")-> select ();
$ This-> assign ('info', $ info );
$ This-> display ();
In this way, we get only the name value.
2; group query, $ info = $ t-> field ("name")-> group ('name')-> select ();
3: sort query: $ info = $ t-> order ("field")-> select (); ascending query.
4: You can also select the data table $ info = $ t-> table ('Table name')-> order ("field")-> select ();
5: limit the number of queries.
6: directly query the primary key select ("primary key value 1, primary key value 2 ");
7: find: returns the result of the one-dimensional array find ('primary key value ');
8: having: it can be used only when select queries are available.
Some aggregate functions, such as sum, count, max, and avg, operate data objects directly.
Actually, we have nothing to do when it comes to integrating smarty. The main thing we need to do is to use the template to allocate various variables...