ThinkPHP single letter function pickup

Source: Internet
Author: User
ThinkPHP single letter function sorting reference source: m-oyzm.iteye.comblog965299A function (basic is the abbreviation of Action) A function is used to instantiate our Action Class, for example, our program has two actions: IndexAction and TestAction. in IndexAction, there is a myHello method that can output hellow ThinkPHP single letter function.
Reference Source: http://m-oyzm.iteye.com/blog/965299

Function(This is the abbreviation of Action)

Function A is Used to instantiate our Action ClassFor example, our program has two actions: IndexAction and TestAction. in IndexAction, there is a myHello method that can output hello world. what if I want to output the same text in TestAction? The original method first imports the file IndexAction. class. php, then new IndexAction, and finally calls the myHello method.

The code is generally:

 MyHello (); // call the myHello () method }?>


So how can we write if we use function?

 myHello();       }   }   ?>


Function B
This is a new function with the emergence of behavior. it can execute an action, such as B ('app _ begin'). it is all the functions defined by this behavior before the project starts, two parameters are supported. The second parameter must accept an array, for example, B ('app _ Begin', array ("name" = & gt; "tdweb ", "time" => time.


C functions

   Get configuration valueThere should be a lot of users. Although easy to use, the C function is undoubtedly a very powerful function.

Get value:
Get all settings: C (); returns an array containing all settings without passing any parameters.
Obtain the specified configuration: C ('URL _ Model') to obtain the configuration information of URL_MODEL.
Obtains the specified two-dimensional array configuration: C ("array. name"), and returns the value corresponding to the key of the array as name.

Set value:
Assign a value to a two-dimensional array C ("array. name", "value"). The principle is the same as above (obtain the value of array. name), and the value behind it is the value.

Batch assignment:
$ Test = array ("URL_MODEL" => 1, "THIN_MODEL" => true ");
C ($ test );
In this way, the values in the array are assigned a value.

Determine whether to assign a value:
C ("? URL_MODEL ") add "? ", Returns true if the value has been assigned.

It should be noted that although the configuration value has been changed here, only the changes made on this page will not work on the next page. if you want to change it, it will be changed permanently, then, you need to use the F function to write the configuration file to config. php.

D function

DAO function should be the most commonly used function for writing programs. Similar to function A, if function D is not used, you need to import the Model, and then new Model. The rest are the same.

However, the D function has two features. One is that if this Model has been instantiated before, it will not be instantiated and there will be resources left. The other is convenient debugging. if this Model does not exist, will throw TP exception, very user-friendly.

If you access the Model of this project, you can directly access D ("Model name"). If you want to access the Model across projects, you can use D ("Model name", "project name "); nothing else can be said.

F function

   Fast reading and saving of file data

   Save data quickly: F ("mydata", "Here is the Data to be saved"). In this way, the project Data directory stores a file named mydata. the content in the php file is the second parameter of the function.

   Save time: F ("mydata", "Here is the data to be saved", "60"). In this way, if you access the file again next time, the cached file will be deleted at an interval greater than 60 seconds.

   Save Directory: F ("mydata", "Here is the data to be saved", "60", DATA_PATH), so that it is specified to be saved in the data directory

   Delete cache now: F ("mydata", null), the second parameter passes a null value, so that the cache mydate is deleted.

   Read cache data: F ("mydata") to read the cache.


L function

Language-defined functions. L ("intro") gets the language defined as intro. l ("intro", "Introduction") assigns values to intro, the same principle is true for C functions.


R functions

Remember our A function. if you only want to execute A method, it is more convenient to use the R function. you can replace it

    


S function

   Global Cache read/write functions, Similar to C, but it is directly written as a file. it is written in the Temp directory. However, note that if the cache name is aaa, the cached file name is the md5 ("aaa") value, which is worth noting.

U function

The U function is a very powerful function. it is mainly used for URL assembly and supports different modes and routes.

For example:
Obtains the Action address of the current module.: U ("/nowMethod ");
Obtain the Action address of the current module and pass the parameter: U ("/nowMethod? Params = test ");

(If you are not used to the above method, you can use U ("/nowMethod", array ("params" => "test"); to pass parameters in an array, the results are the same)

Access other modules: U ("Other/otherMethod"). This is the otherMethod method used to access the Other module.
Cross-Project Access: U ("appname: // Other/otherMethod ");
Use Route access: U ("appName: // routeName @ moduleName/actionName? Params ");

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.