Some tips and tricks for using thinkphp

Source: Internet
Author: User
Keywords thinkphp
Tags aliyun class data file files find html http

I found some ideas and techniques to use thinkphp to share with you
It's not even mentioned in some manuals.

Agreed:
1. All class library files must use the. class.php as the file suffix, and the class name and file name remain the same
2. Controller class name with http://www.aliyun.com/zixun/aggregation/16339.html ">action" as suffix
3. The class name of the model is suffix, the first letter of the class name must be capitalized
4. database table names are all lowercase,

As:
Data table Name: prefix _ table name
Model Class Name: Table name Model NOTE: This is the first letter of the table name to be capitalized
Create object: D (' table name ') Note: Here's the first letter of the table name to capitalize

Defining controller Classes
Class Indexaction extends action{
Public function Show () {
Echo ' This is the new show operation ';
}
}
And then enter it in the browser.
http://localhost/myApp/index.php/Index/show/

To define a model class:
Class table name Model extends model{
[///manually define fields [optional]
Protected $fields = Array (
' ID ',
' Username ',
' Email ',
' Age ',
' _PK ' => ' id ',//primary key
' _autoinc ' =>true//self-increasing
)
]
}

Changes to records:
$User = D ("user")//Instantiate User Object
$User->find (1)//Find a record with ID 1
$User->name = ' thinkphp '//Change the Name field of the found record to thinkphp
$User->save ()//Save modified data
Update values for specific fields
$User->setfield (' name ', ' Topthink ', ' id=1 ')
You can also support operations on fields
$User->setfield (' Score ', ' (score+1) ', ' id=1 ')

Related Article

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.