thinkphp Study Notes

Source: Internet
Author: User

Front and rear configuration :

Create a Conf folder in the root directory folder

Conf folder to create a config.php file, which stores public configuration information, convenient front and back calls.

Simple definition 404 page

Pseudo-static removal . html

Config in url_html_suffix = "

assigning templates

1: $this->assign (' XXX ', $XXX);

2: $this->a = 111;

3: $this->assign (' xxx ', $xxx)->display ();

Time stamp Processing

{$v. time|date= ' y-m-d h:i ', # # #}

Group:

file names that are used separately under the common folder after grouping should be function.php rather than common.php

JS External address cannot parse U function :

Html page :

Non-application group notation :

Apply group Wording

Behind an empty for processing pseudo-static . html removal . html

Js page:

Error page customization:

under the Conf folder

Data deposit:

1)

2):

Data read:

1):

2):

Random number :

Mt_rand (Min,max);

U method to remove . html End

Verification Code Production :

SESSION Deposit Database :

1): in the configuration file

2): Create a database table :

Thinkphp a variety of methods commonly used

A () load Action class
D () load Model class
S () Global cache configuration
L () Get the language definition
C () Get configuration values
F () fast file data reading and saving for simple type data strings, arrays
U () to complete the assembly of the URL address
I () quickly create an object instance

1.A Quick Create Action Object

$action =new useraction ();// equivalent to the following wording : $action =a ("User"); also, if the current useraction class has not yet been introduced, A method is automatically introduced. And with singleton mode support, the same Action object is not created repeatedly .

the A method supports cross-project calls, such as:

$action =a ("User", ' Admin '); Instantiate the useraction class for the Admin project

2.d  Quick Create Model data Object
 
Define the model class first, such as usermodel d () Span style= "font-family: the song Body;" > function to manipulate the data. For example:
 ,
First in " your project "/lib/model Span style= "FONT-FAMILY:CALIBRI;" >usermodel.class.php php script with the following:
 
class usermodel extends  model{}

Then, without adding any properties and methods, you can do the following:

$User =d ("User"); Instantiate the user object,user is the one you created in the database named " prefix _user" Data Sheet, you can also use the $User =new Usermodel () instead, perform an instantiation of the object's operation. After the instantiation, you can make additions and deletions to the data, such as a series of operations, such as:

$User->find (1); Find records with primary key 1

We need to add 1 to the specified field when we are making user coins or points or voting. so I can write that .

$User->score= ' (score+1); $s->save (); This will save us a lot of steps.

If you want to modify a specified field, you can abbreviate it as follows:

D (' User ')->setfield (' name ', ' hehe ', ' id=2 ');

The difference between the D method and the M method is mainly:

The M method does not need to create a model class file,and them method does not read the model class, so automatic validation is not valid by default, but can be implemented by dynamic assignment, whereas the D method must have a model class created. We can use the following two ways to create a mapping object for a data table.

The first type:$Test =d (' Test ');

The second type:$Test =new Model (' Test ');

Although both of these can be operation, in the data validation is very different, in the first instance of a model in the   will have data inspection functions, such as can be defined if   title   "  ( This is TP an automatic verification feature provided, of course, is also required in the corresponding   define validation criteria )

the D method can automatically detect the model class, and he throws an exception when it does not exist. At the same time, the instantiated model is not repeated ( singleton ). The default D method can only support calls to models under the current project ( or Application ) . For example:

$user =new Usermodel ();

Equivalent to $user =d (' user ');

If an empty model is instantiated, for example:

$Demo =new Model ();

Then it is equivalent to:

$Demo =m ();
 
3.s  quick-Action caching method
 
Thinkphpthinkphp unify all the caching mechanisms into one s method to do this, so there is no need to focus on specific cache details when using different caching methods. such as:

S (' data ', $Data); Cache $Data data with data identity
S (' Data ', $Data, 3600); Cache $Data data 3600 sec
$Data =s (' Data '); Get Cached Data
S (' name ', null); Remove Cache identity name

4.L Quick-action language variables

The L method provides multi-language support to quickly set up and get language definitions.

l (' user_info ', ' get user_info
// bulk assignment  
$array [' user_info ']= '

5.C Quick Action configuration variable, using C (" fill in the index of the array in the configuration file ")

C (' user_auth_on ', true); setting configuration parameters with name user_auth_on
C (' user_auth_on '); gets The variable value of the user_auth_on

Same as L , C also supports batch assignment

Note: Configuration parameters are case insensitive

Also starting with the 1.5 version,theC method supports the operation of a two-dimensional array, for example:

C (' USER. User_type ', 1);
C (' USER. User_auth_on ');

6. F File Data preservation method

The F method is mainly used for writing, changing, and deleting the file data of the project, its working mechanism is similar to the S method, the difference is that the data is saved in different directories, and the cache mode cannot be specified, because the default is to save the data in the form of file. the F method uses the var_export method, so only simple data types are supported, and object caching is not supported.

7. U is used to complete the assembly of the URL address, the feature is that it can automatically generate the corresponding URL address According to the current URL pattern and Settings

The function is in the following format:U ('Address', 'Parameters', 'pseudo-Static', 'whether to jump', 'Show domain name');use in TemplatesUmethod rather than fixed write deadURLthe advantage of an address is that once your environment changes or parameter settings change, you don't need to change any of the code in the template. The calling format in the template requires the use of the{: U ('Address', 'Parameters' ...)} the way.

example of the use of the U method:

U (' user/add ')// generate add action address for User module

You can also support grouping calls:

U (' home/user/add ')// generate The add action address of the User module for the Home Group

Of course, it can be just a write operation name, which means that the current module is called

U (' add ')//Generate Add action address for current access module

In addition to grouping, modules, and operation names, we can also pass in some parameters:

U (' blog/read?id=1 ')// generate a read operation for the Blog module and ID 1 the URL address

the second parameter of the U method supports passing arguments, supports both array and string definitions, and if only a string-only parameter can be defined in the first argument, the following are equivalent:

U (' blog/cate ', Array (' cate_id ' =>1, ' status ' =>1))
U (' blog/cate ', ' Cate_id=1&status=1 ')
U (' Blog/cate?cate_id=1&status=1 ')

Import css/js file

<js href= "__public__/js/common.js"/>

<css href= "__public__/css/common.css"/>

thinkphp Study Notes

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.