在 zend 框架中的 zend_auth 存储中添加变量(不是 setTableName() 中给出的表的属性)
我的代码如下:
$authAdapter = $this->getAuthAdapter();
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
其中 getAuthAdapter() 如下:
protected function getAuthAdapter() {
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('credentials')
->setIdentityColumn('employee_id')
->setCredentialColumn('password');
return $authAdapter;
}
$userInfo = $authAdapter->getResultRowObject(null, 'password');
# the default storage is a session with namespace Zend_Auth
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
这里我使用了名为凭据的表。但是我想在 auth_storage 中存储一个变量,该变量不是表凭据的属性。这样我以后就可以使用该变量存储如下。那么这应该如何完成?
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
我可以通过以下代码来完成: 如果我想添加一个名为 $var 的变量,那么
$var = new stdClass;
$userInfo->var = 'Variable';
但我认为这不是个好主意。还有其他解决方案吗?请快速回复,因为它迫切需要。提前致谢。
I have the code as:
$authAdapter = $this->getAuthAdapter();
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
where getAuthAdapter() is as follows:
protected function getAuthAdapter() {
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('credentials')
->setIdentityColumn('employee_id')
->setCredentialColumn('password');
return $authAdapter;
}
$userInfo = $authAdapter->getResultRowObject(null, 'password');
# the default storage is a session with namespace Zend_Auth
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
Here I have used table named credentials.But I want to store a variable in auth_storage which is not the attribute of table credentials.So that I can use that variable later from that storage as given below.So how this should be done??
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
I can do by the following code:
If I want to add a variable named $var then
$var = new stdClass;
$userInfo->var = 'Variable';
But I dont think its good idea.Any other solution ??Please reply fast as its urgently required.Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想存储数据库中其他表的一些数据,您可以获取身份验证选择实例并与该表连接:
If you want to store some data from other table from database you can get an instance of authentication select and join with that table(s):