ThinkPHP framework utility _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
ThinkPHP framework. III. Utility 1. in the php program, if you want to use the session technology, you must first enable sessionSession_start (); in the tp, the session mechanism is enabled by default.

1. session

In a php program, if you want to use the session technology, you must first enable the session

Session_start ();

In tp, the session mechanism is enabled by default.

If the session technology is not used in our program, we recommend that you disable the session in the configuration file.

L config. php

SESSION_AUTO_START

Enabled by default

L session ('name', 'value ');

Create a session and assign values

Name: Name

Value: Value

L $ value = session ('name ');

Set the session value

Name: Name

L session ('name', null );

Clears the specified session.

L session (null );

Clear all sessions

L session ('? Name ');

Determines whether a specified session exists.

2. cookie

L cookie ('name', 'value ');

Create cookie

L cookie ('name', 'value', 3600 );

Create a cookie and set the time to live

L $ value = cookie ('name ');

Cookie value

L cookie ('name', null );

Clears the specified cookie.

L cookie (null );

Clear all cookies

3. verification code

To generate a Chinese verification code, you need to call the GBVerify method in the image class to generate the code. to call this method, you need to put the corresponding font files in the library in the same directory as the image class.

Create an operation on the controller to generate a verification code:

In the form, use the src attribute of the image to call the above operations

During verification, because the default verification code session is encrypted by md5, we need to encrypt the verification code submitted by the user before comparison.

4. data paging

Parameters of the setConfig method:

L header

L Prev

L next

L first

L last

L $ page-> setConfig ('header', 'Member ');

5. multi-table join

L table

Select t1. *, t2. * from t1, t2 where t1.id = t2.sid

L join

Select t1. *, t2. * from t1 left join t2 on t1.id = t2.sid

1) table syntax:

L table

L $ model-> table ('table1 t1, table t2 ')

-> Where ('t1. id = t2.sid ')

-> Select ();

2) join syntax:

L $ model-> join ('left (right) join t2 on t1.sid = t2.id ')

-> Select ();

6. Ajax applications

L The Action class provides the ajaxReturn method for returning data to the client after AJAX is called.

L configure DEFAULT_AJAX_RETURN to set the returned data in JSON format by default.

Session 1. in the php program, if you want to use the session technology, you must first enable session Session_start (); in tp, the session mechanism is enabled by default if our program...

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.