gpt4 book ai didi

php - 如何在 zend 框架中设置 auth 变量

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:50 25 4
gpt4 key购买 nike

我们正在使用 ZendFrame 开发一个网站。

我们需要设置一个授权变量(角色)来管理用户类型。

为此,我们使用变量 this->view->auth->getIdentity()->role 来管理用户类型。

在一个追逐中,我们试图静态分配用户类型。

分配 auth 变量“role”的代码是什么。

我们尝试使用 this->view->auth->getIdentity()->role = 'test',但通过了警告。

最佳答案

以下应该允许您在成功登录后创建一个新的 Zend_Auth 身份:

$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($userData);

至于用户数据,我通常存储与用户对应的数据库行,其中包含姓名、姓氏、电子邮件、角色等必填字段,仅举几例。如果你在 Zend_Auth 中存储一个 Zend_Db_TableRow 你将能够像这样访问它:

Zend_Auth::getInstance()->getIdentity()->role;

关于 Zend_Auth 的快速提醒:

$auth = Zend_Auth::getInstance(); // get the `Zend_Auth` instance (build on the singleton pattern)

$auth->hasIdentity(); // return true if an indentity exists and false if it doesn't

$auth->getIdentity(); // allow you to get the identity content (array, Zend_Db_TableRow and such)

$auth->write($data): // allow to create a new identity

$auth->clearIdentity(); // destroy any content stored in the identity. Zend_Session::destroy() can also be used since identity is stored in a session variable

有关更多信息,请阅读官方文档:Zend_Auth

关于php - 如何在 zend 框架中设置 auth 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com