【问题标题】:CakePhp Auth session data: dot notation not workingCakePhp Auth 会话数据:点表示法不起作用
【发布时间】:2013-03-20 05:18:46
【问题描述】:

如果我将以下代码添加到控制器操作并访问它:

debug($this->Session->read('Auth.User'));

如果看到以下打印:

array(
    'User' => array(
        'password' => '*****',
        'username' => 'admin'
    )
)

但如果我尝试使用点符号访问“用户名”:

debug($this->Session->read('Auth.User.username'));

它返回空值。

我在这里错过了什么?

【问题讨论】:

  • 您缺少登录网站...确保您使用有效的用户名和密码登录...
  • 试试这个调试($this->Session->read('Auth.User.User.username'));

标签: php session cakephp authentication


【解决方案1】:

试试这个debug($this->Session->read('Auth.User.User.username'));

【讨论】:

  • 知道为什么 Auth.User 会话数组中没有 id 吗?它作为主键存在于 db 表中:?
  • 请试试这个 $userid =$this->Auth->user('id');或 $userId = $this->Session->read('User.id');
  • $this->Auth->user 和 $this->Session->read('User') 都调试为 null。
  • 啊我错过了这部分:) :book.cakephp.org/2.0/en/core-libraries/components/… '请务必手动将新的用户 ID 添加到传递给登录方法的数组中。否则,您将无法获得可用的用户 ID'
猜你喜欢
  • 2013-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多