thinkphp Framework's Utility _php tutorial

Source: Internet
Author: User
Iii. Practical Items

1. Session

In a PHP program, if you want to use session technology, you must first open the session

Session_Start ();

In TP, the session mechanism is turned on by default

If the session technology is not used in our program, it is recommended to switch the session in the configuration file

L config.php

Session_auto_start

The default is open

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

Create session and assign values

Name: Name

Value: Values

L $value = Session (' name ');

Take a value on the session

Name: Name

L session (' name ', null);

Clears the specified session

L session (NULL);

Clear all session

L session ('? name ');

Determines whether the specified session exists

2. Cookies

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

Create a cookie

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

Create a cookie and set the time to live

L $value = cookie (' name ');

To value a cookie

L Cookie (' name ', null);

Clears the specified cookie

L cookie (NULL);

Clear All Cookies

3. Verification Code

If you need to generate a Chinese verification code, you need to call the image class under the Gbverify method to build, call this method needs to be in the font library of the corresponding font file in the same directory as the image class

Create an action in the controller that is specifically used to generate the verification code:

In the form, use the SRC attribute of the image to invoke the above action

Verification, because the default verification code session through MD5 encryption, so the comparison, we need to the user submitted verification code is also encrypted, and then compare

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 Connection

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 "join T2 on T1.sid=t2.id ')

->select ();

6. AJAX Applications

The L Action class provides the Ajaxreturn method for returning data to the client after an AJAX call

L set by Configuration Default_ajax_return, the default configuration returns data in JSON format

http://www.bkjia.com/PHPjc/477230.html www.bkjia.com true http://www.bkjia.com/PHPjc/477230.html techarticle Third, utility 1, session in the PHP program, if you want to use the session technology must first open session session_start (); In TP, the session mechanism is open by default if we 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.