如何使用cakephp(MVC)创建会话

如何使用cakephp(MVC)创建会话,php,cakephp,Php,Cakephp,我想知道如何创建会话从我的不同用户登录后,如果有一个功能,请让我知道。 我的登录功能是: public function login() { if ($this->request->is('post')) { if ($this->Auth->user('id')) { $this->Flash->error('Already logged in'); } else {

我想知道如何创建会话从我的不同用户登录后,如果有一个功能,请让我知道。 我的登录功能是:

public function login()
{
    if ($this->request->is('post')) {
        if ($this->Auth->user('id')) {
                $this->Flash->error('Already logged in');
            } else {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl('/users/index'));

        }
        $this->Flash->error('Votre identifiant ou votre mot de passe est incorrect.');
        }
        }
}

使用$this->Auth->setUser($user)用户登录,即将用户信息保存到会话

您可以访问CakePhp 3.x中的会话

对于用户id:

$this->request->Session()->read('Auth.User.id')


您阅读过手册中的会话吗?您不必手动创建会话。你面临的确切问题是什么?