【问题标题】:How do I get my Authenticated user info? As Id and such?如何获取经过身份验证的用户信息?作为Id之类的?
【发布时间】:2020-04-14 00:15:26
【问题描述】:

我是最新的 cakephp 版本的新手,直到现在才使用身份验证组件。我正在尝试验证用户是否是管理员,但找不到如何获取用户 ID 来获取它,也找不到如何获取标识符。 $this->Authentication->getIdentifier() 抛出标识符不存在的错误。

总的来说,我正在尝试做一些 cms 来学习新的框架用法等。从 2.x 开始就没有使用过它

【问题讨论】:

标签: authentication cakephp-4.x


【解决方案1】:

获取 id 是 $this->Authentication->getIdentity()->getIdentifier()。您还可以使用 get() 方法获取其他字段,例如 $this->Authentication->getIdentity()->get('username') 返回用户名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多