无法使用CakePHP 4中的setUser在Auth中设置用户
在CakePHP4.0中 当我尝试执行无法使用CakePHP 4中的setUser在Auth中设置用户,php,cakephp,cakephp-4.x,Php,Cakephp,Cakephp 4.x,在CakePHP4.0中 当我尝试执行$this->Auth->setUser($user)时,出现以下错误: \cakephp\cakephp\src\Http\Session.php-参数1传递给 Cake\Http\Session::\u overwrite()必须是受保护的数组类型 函数_覆盖(数组&$old,数组$new):无效 这是我的代码: $user = $this->Auth->identify(); if ($user) { $this->Auth-
$this->Auth->setUser($user)
时,出现以下错误:
\cakephp\cakephp\src\Http\Session.php-参数1传递给
Cake\Http\Session::\u overwrite()必须是受保护的数组类型
函数_覆盖(数组&$old,数组$new):无效
这是我的代码:
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
}
当我尝试var\u dump($user)
时,它包含用户详细信息
请帮助我无法传入数组,因为$user不是数组此问题既不是由于以前生成的输出(在我的情况下是警告)或会话的其他错误配置造成的。 当您仔细查看Session.php,尤其是write()方法时,您将看到这部分代码:
if (!$this->started()) {
$this->start(); //this may result in false but cakephp ignores it here...
}
$this->_overwrite($_SESSION, $data); //will fail for no session_start() has been invoked yet
因此,即使您的会话尚未启动,脚本也将进一步处理,这将导致错误消息。
因此,请检查您是否可以通过此测试:
if (ini_get('session.use_cookies') && headers_sent()) {
//error headers already send
}
只要您不传递它,您就无法将任何数据写入会话您没有使用身份验证插件吗?AuthenticationPlugin附带setIdentity。您将使用setIdentity而不是setUser。您可以为此提供链接吗?