CakePHP Framework Session Setting method

Source: Internet
Author: User
This paper describes the CakePHP framework session setting method. Share to everyone for your reference, as follows:

CakePHP Session Storage Options

CakePHP provides users with 3 ways to save session data:

1. CakePHP installs the temporary documents under this document;
2. Use PHP's default mechanism;
3. Or serialize to the database.

The corresponding settings in core.php are:

Define (' Cake_session_save ', ' php '), # set to ' CAKE ', save SESSION to/cakedistro/tmp directory # set to ' php ', with php default path # set to ' database ',

The default is the PHP mechanism.

If you choose to store in a database, you need to create a table in the database and a SQL script that creates the database in/app/config/sql/sessions.sql.

Regardless of which session storage method you choose, CakePHP's component approach operations are basically the same:

CakePHP session component is used to interact with the session: including basic session reading and writing, prompting for errors via session, prompting messages, and so on.

Session component is available by default in all Cake controllers.

check(string $name);

Check to see if there are data items in the session that have $name as key values.

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

Deletes the Session variable specified by $name.

error

Returns the most recent error generated by the Cake Session Component, often used for debugging.

flash(string $key='flash');

Returns the message set with Setflash () in the last session. If $key is set, the message that is most recently stored is returned.

read(string $name);

Returns the value of the $name variable.

renew

Update the information in the previous session to the new session by creating a new Seesion ID, deleting the original ID.

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

Writes the information in the $flashmessage to the session (for later Flash () methods to get it).

If the $leyout is set to "default", the message is stored as ' <p class= ' > '. $flashMessage. ' </p> '. If $layout is set to ', the message is saved as-is. If $layout to a different value, the message is saved in the Cake view in the format specified by the $layout.

$params parameters will be given functionality in a future release.

$key allows you to store a prompt message under a key, and Flash () reads the message based on the key.

Valid returns True when the session is valid, preferably before the read () operation to determine whether the session you are trying to access is actually valid.

write(string $name, mixed $value);

$name the variable $value write to the session.

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.