Thinkphp summary, thinkphp

Source: Internet
Author: User

Thinkphp summary, thinkphp

After using ThinkPHP for several projects, I feel that this framework is quite good and suitable for my logic habits. It is also quick to develop. I have summarized some of the frequently used projects, hope to help beginners TP!

1. tags not available in the template

{$ Content} {$ I}

2. If tag

For example: <if condition = "$ name eq 1">

There are always unexpected errors after the test, so it is better to use them directly <? Php if (...) {...?> Faster.


1. All class library files must use. class. php as the file suffix, and the class name and file name must be consistent.

2. The class name of the controller is suffixed with Action.

3. The Model class name is suffixed with Model. The first letter of the class name must be capitalized.

4. All database table names are in lower case,

For example:

Data Table Name: prefix _ table name

Model Class Name: Table Name Model note: the first letter of the table name must be capitalized.

Create object: D ('table name') Note: The first letter of the table name must be capitalized.

Define controller class

Class IndexAction extends Action {

Public function show (){

Echo 'this is the new show operation ';




Http: // localhost/myApp/index. php/Index/show/

Define model class:

Class table name Model extends Model {

[// Manually define a field [Optional]

Protected $ fields = array (

'Id ',

'Username ',

'Email ',

'Age ',

'_ PK' => 'id', // primary key

'_ Autoinc' => true // whether to auto-Increment




Record modification:

$ User = D ("User") // instantiate the User object

$ User-> find (1) // search for records with id 1

$ User->

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: 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.