ThinkPHP template output and model usage _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The output of the thinkPHP template and the use of the model. A. Use echo and other PHP native output methods to output B on the page. Use assign method c to distribute variables through the display method, modify the left and right delimiters, and modify the configuration file. echo and other PHP native output methods are output on the page
B. output through the display method
You can use the assign method to allocate variables.
C. modify the left and right delimiters
Do not modify the configuration items in the configuration file
'Tmpl _ L_DELIM '=>' <{', // modify the left delimiter
'Tmpl _ R_DELIM '=>'}> ', // modify the right delimiter

II. Use of ThinkPHP 3 models (important)
You need to operate the database in the form of new Model (table name) in the method
$ M = new Model ('user ');
$ Arr = $ m-> select ();
'Db _ type' => 'mysql', // Set the database TYPE
'Db _ host' => 'localhost', // Set the HOST
'Db _ name' => 'thinkphp', // Set the database NAME
'Db _ user' => 'root', // Set the USER name
'Db _ pwd' => '', // Set the password
'Db _ port' => '123', // Set the PORT number
'Db _ prefix' => 'TP _ ', // you can specify a table PREFIX.

You can also use the DSN method for configuration.

'Db _ DSN '=> 'MySQL: // root: @ localhost: 3306/thinkphp', // configure database information using DSN
If both methods exist at the same time, the priority is given to the DSN method.

There is also a simple and practical model method
M () is equivalent to new Model ();
$ M = M ('user ');
$ Arr = $ m-> select ();

A model instance can be used to operate on data. The operation generally involves adding, deleting, modifying, and querying the database CURD.

Add-C Create $ m-> add ()
Delete-D delete $ m-> Delete ()
Change-U Update $ m-> save ()
Query-R Read $ m-> select ()

III. Supplement (understanding)
A. The template can traverse arrays.

<{$ Vo. id}> ---- <{$ vo. username}> ----- <{$ vo. sex}>


B. We can enable page_trace in the debugging function.
1. enable debugging
// 3. enable the debugging mode
Define ('app _ debug', true );
2. we need to set the configuration file to enable page trace
'Show _ PAGE_TRACE '=> true, // enable page Trace

Echo and other PHP native output methods output B on the page. if you want to allocate variables through the display method output, you can use assign method c to modify the left and right delimiters. you need to modify the configuration file...

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.