Login 记得我用cakephp3吗

Login 记得我用cakephp3吗,login,cakephp-3.x,Login,Cakephp 3.x,我执行此代码时出错 我的错误是调用布尔函数上的成员函数read() 这是函数登录的代码: public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); if ($th

我执行此代码时出错 我的错误是调用布尔函数上的成员函数read() 这是函数登录的代码:

 public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            if ($this->request->data['rememberMe']=="on") {

                $cookie = [];
                $cookie['username'] = $this->request->data['email'];
                $cookie['password'] = $this->request->data['password'];
                $this->Cookie->write('rememberMe', $cookie, true, "1 week");
                unset($this->request->data['rememberMe']);
            }
            if (empty($this->data)) {
                $cookie = $this->Cookie->read('rememberMe');
                if (!is_null($cookie)) {
                    $this->request->data = $cookie;
                    $user = $this->Auth->identify();
                    if ($user) {
                        $this->Auth->setUser($user);
                        $this->redirect($this->Auth->redirectUrl());
                    } else {
                        $this->Cookie->destroy('rememberMe'); # delete invalid cookie

                        $this->Session->setFlash('Invalid cookie');
                        $this->redirect('login');
                    }
                }
            }

            return $this->redirect($this->Auth->redirectUrl());
        }
        else
        $this->Flash->error(__("Nom d'utilisateur ou mot de passe incorrect, essayez de nouveau."));
    }
}
我在“data['rememberMe']==1”上更改了
data['rememberMe']==1”

另一个错误显示为调用布尔函数上的成员函数write()Hi@Ikbel您试图在
AppController.php
中添加
Cookie
组件吗

  public function initialize()
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('Cookie');
    }
文件:

如果在模板登录中使用复选框替换“
上的
$this->request->data['rememberMe']==”到
$this->request->data['rememberMe']==1

并将
$this->Cookie->destroy
替换为
$this->Cookie->delete

对于您的错误: 在布尔值“$this->Session->setFlash('Invalid cookie');”上调用成员函数setFlash()

替换为:$this->Flash->error(('Invalid cookie');
$this->Flash->错误(
(“用户名或密码不正确,请重试”)

Hi@Bed0skil我在5月份添加了cookie组件AppControllerHi@Ikbel,如果你需要使用
cookies
现在就好了,但是如果你想让你的用户登录,请查看它
$this->loadComponent('Auth')它将自动创建
Auth
cookie。看这个完整的嗨,我的问题不是登录到我的用户,我想当我点击复选框“记住我”时,用户名和密码会存储到下一个日志中。你当前的错误是什么?在布尔值上调用成员函数write()?错误已更改为在布尔值“$this->Session->setFlash('Invalid cookie');”上调用成员函数setFlash()