CakePHP framework Session setting method

Source: Internet
Author: User
This article mainly introduces the Session setting method of the CakePHP framework, and analyzes common Session operation skills and related precautions of CakePHP in combination with the specific instance form, for more information about how to set the Session of the CakePHP framework, see the example in this article. We will share this with you for your reference. The details are as follows:

CakePHP Session storage options

CakePHP provides three Session data storage methods:

1. temporary files under the CakePHP installation project;
2. use the default PHP mechanism;
3. or serialized to the database.

The corresponding settings in core. php are as follows:

Define ('Cake _ SESSION_SAVE ', 'php'); # set it to 'cake', save the session to the/cakedistro/tmp Directory # set it to 'php ', use the default PHP path # set it to 'database ',

PHP is used by default.

If you choose to store data in the database, you need to create a table in the database. the SQL script for creating the database is available in/app/config/SQL/sessions. SQL.

No matter which Session storage method is selected, CakePHP's component methods are basically the same:

CakePHP Session Component is used to interact with Sessions, including basic Session read/write, error prompting through sessions, and prompt messages.

Session Component is available by default in all Cake controllers.

check(string $name);

Check whether $ name is a key value in the Session.

del(string $name);
delete(string $name);

Delete the Session variable specified by $ name.

error

Returns an error recently generated by the Cake Session Component, which is often used for debugging.

flash(string $key='flash');

Return the message set with setFlash () in the last Session. If $ key has been set, the message recently stored in it will be returned.

read(string $name);

Returns the value of $ name.

renew

Create a new seesion ID, delete the original ID, and update the information in the original Session to the new Session.

setFlash(string $flashMessage, string $layout='default', array $params, string $key='flash');

Write the information in $ flashMessage to the Session (which can be obtained by The flash () method ).

If $ leyout is set to "default", the message is stored'

'. $ FlashMessage .'

'. If $ layout is set to '', the message is saved as is. If $ layout is another value, the message is saved in the Cake view in the format specified by $ layout.

The $ params parameter will be assigned a feature in future versions.

$ Key allows you to store the prompt message under the key. flash () reads the message based on the key.

Valid returns true when the Session is valid. it is best to use it before the read () operation to determine whether the Session you want to access is indeed valid.

write(string $name, mixed $value);

Write the variable $ name and $ value to the session.

For more information about how to set the Session of the CakePHP framework, refer to the Chinese PHP website!

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.