Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在zend framework中设置auth变量_Php_Zend Framework_Authentication - Fatal编程技术网

Php 如何在zend framework中设置auth变量

Php 如何在zend framework中设置auth变量,php,zend-framework,authentication,Php,Zend Framework,Authentication,我们正在开发一个使用ZendFrame工作的站点 我们需要设置一个auth变量(role)来管理用户类型 为此,我们使用变量this->view->auth->getIdentity()->role来管理用户类型 在一次追逐中,我们试图静态地分配用户类型 分配auth变量“role”的代码是什么 我们尝试了this->view->auth->getIdentity()->role='test',但是它通过了警告。以下内容应该允许您在成功登录后创建一个新的Zend\u auth身份: $ident

我们正在开发一个使用ZendFrame工作的站点

我们需要设置一个auth变量(role)来管理用户类型

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

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

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


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

以下内容应该允许您在成功登录后创建一个新的
Zend\u auth
身份:

$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($userData);
至于用户数据,我通常存储与用户对应的数据库行,其中包含名称、姓氏、电子邮件、角色等必填字段。如果在
Zend\u Auth
中存储
Zend\u Db\u 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
有关更多信息,请阅读官方文档: