在 zend 框架中的 zend_auth 存储中添加变量(不是 setTableName() 中给出的表的属性)

发布于 2024-12-27 12:11:54 字数 1298 浏览 1 评论 0原文

我的代码如下:

            $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫多说 2025-01-03 12:11:54

如果您想存储数据库中其他表的一些数据,您可以获取身份验证选择实例并与该表连接:

$authSelect = $authAdapter->getDbSelect();
$authSelect->join(TABLE, CONDITION, COLUMNS);

$result = $auth->authenticate($authAdapter);

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):

$authSelect = $authAdapter->getDbSelect();
$authSelect->join(TABLE, CONDITION, COLUMNS);

$result = $auth->authenticate($authAdapter);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文