作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我们正在使用 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/
我是一名优秀的程序员,十分优秀!