ThinkPHP integrates the usage and query methods of the Smarty template engine. _ PHP Tutorial

Source: Internet
Author: User
Tags smarty template
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.