Significance of C, D, S in thinkphp

Source: Internet
Author: User
1. in the specific Action method, you can use C () to dynamically configure some parameters, mainly those that are not yet used. The usage is as follows:

1. in the specific Action method, you can use C () to dynamically configure some parameters, mainly those that are not yet used. The usage is as follows:

C ('parameter name'); // Obtain the set parameter value

C ('parameter name', 'New parameter value'); // you can specify a new value.

 

2. use of D () functions:

Define the model class, such as UserModel, and then use the D () function to operate the data. For example:

First, create a php script named UserModel. class. PHP under "your project" \ Lib \ Model. the content is as follows:

Class UserModel extends Model {}

Then, you can perform the following operations without adding any attributes and methods:

$ User = D ("User"); // instantiate the User object. User is a data table created in the database named "prefix _ user ".

You can also use $ User = new UserModel () instead to instantiate an object.

After instantiation, you can add, delete, query, modify, and perform a series of operations on the data, such:

$ User-> find (1); // query records whose primary key is 1

 

Use of the 3. S () function:

ThinkPHP abstracts various cache methods into uniform cache classes for calling, and ThinkPHP unifies all cache mechanisms into one S method for operations.

Different caching methods do not need to focus on specific cache details. For example:

S ('data', $ data); // use the Data identifier to cache $ data Data

S ('data', $ data, 3600); // cache $ Data for 3600 seconds

$ Data = S ('data'); // Obtain cached data

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.