The example in this article describes the CakePHP framework Session setting method. Share it with everyone for your reference, the details are as follows:
CakePHP Session storage options
CakePHP provides users with 3 ways to save Session data:
1. Temporary files in the CakePHP installation directory;
2. Use the default mechanism of PHP;
3. Or serialize to the database.
Corresponding settings In core.php they are:
define('CAKE_SESSION_SAVE', 'php'); # 設(shè)置為 'cake',保存session到 /cakedistro/tmp目錄 # 設(shè)置為 'php',采用PHP的缺省路徑 # 設(shè)置為 'database',
The PHP mechanism is used by default.
If you choose to use it in the database For storage, you need to create a table in the database. There is a sql script to create the database in /app/config/sql/sessions.sql.
No matter which Session storage method is chosen, the component method operation of CakePHP is basically the same :
CakePHP Session Component is used to interact with Session: including basic Session reading and writing, prompting errors through Session, issuing prompt messages, etc.
Session Component is the default in all Cake controllers Available.
check(string $name);
Check whether there is already a data item with $name as the key value in the Session.
del(string $name);<br>delete(string $name);
Delete the Session variable specified by $name.
error
Returns the most recent error generated by Cake Session Component, often used for debugging.
flash(string $key='flash');
Returns the last message set with setFlash() in Session. If $key is set, the most recently stored message in it will be returned.
read(string $name);
Returns the $name variable value.
renew
By creating a new seesion ID, deleting the original ID, and updating the information in the original Session to the new Session.
setFlash(string $flashMessage, string $layout='default', array $params, string $key='flash');
Set $flashMessage in The information is written to the Session (for subsequent flash() method to obtain).
If $leyout is set to "default", the message is stored as '
'. If $layout is set to '', the message will be saved as is. If $layout is any other value, the message is saved in the Cake view in the format specified by $layout.$params parameters will be given functionality in future versions.
$key allows the prompt message to be stored under the key, and 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 variables $name, $value into the session.
For more articles related to the CakePHP framework Session setting method, please Follow PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Validator can be created by adding the following two lines in the controller.

This chapter deals with the information about the authentication process available in CakePHP.

In this chapter, we are going to learn the following topics related to routing ?

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

To work on file upload we are going to use the form helper. Here, is an example for file upload.
