【问题标题】:Get all session data in zend 1.12获取zend 1.12中的所有会话数据
【发布时间】:2014-07-08 18:15:09
【问题描述】:

大家早上好,我有以下代码,它总是在视图上返回值“方向”,但我想检索数据花瓶的所有值并将其放到会议上,因为我能做到,他们提前谢谢你。

控制器:

$authAdapter = new Zend_Auth_Adapter_DbTable();

$authAdapter
    ->setTableName('credential')
    ->setIdentityColumn('email')
    ->setCredentialColumn('password')
    ->setIdentityColumn('direccion');

$authAdapter
    ->setIdentity($form->getValue('email'))
    ->setCredential($form->getValue('password'))
    ->setIdentity('San marcos');
    $select = $authAdapter->getDbSelect();
            $select->where('status = "1"');

$auth = Zend_Auth::getInstance();

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

查看:

if (Zend_Auth::getInstance()->hasIdentity()) {
    $username = Zend_Auth::getInstance()->getIdentity();
    $profile = 'Welcome, ' . var_dump($username) . ' <a href="/auth/public/user/logout">logout</a>';
} else {

【问题讨论】:

  • Sooo...问题到底是什么?
  • 你好@PatrickQ 想获取我数据库的几个参数,存储在会话中,然后在另一个页面上显示。
  • 这不是问题。
  • @PatrickQ 这个很好,如何在会话 Zend_Auth 中保存多个参数?
  • 可能是我解释的不太好,英语也不太会说。

标签: php zend-framework zend-auth


【解决方案1】:

您可以在 zend_auth 上为当前用户编写自己的 LoginStorage 类。 这样,当您对用户进行身份验证时,使用 Zend_auth 上的自定义值写入 LoginStorage。

类似这样的:

<?php
//LoginStorage custom class
class LoginStorage {

public function __construct ($direccion){
     $this->direccion = $direccion;
}

public $direccion;

}

所以当你运行 auth 时:

...
if (Zend_Auth::getInstance()->authenticate($myAuthAdapter)->isValid()) {

   //Instance of UNIQUE auth -> get session writer to record authentication rowset
   Zend_Auth::getInstance()->getStorage()->write(new LoginStorage($myDireccionForThisUser));
...

现在,当您获得Zend_Auth::getInstance()-&gt;getStorage()-&gt;read() 时,您就可以使用一个 LoginStorage 对象了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 2022-09-27
    • 1970-01-01
    相关资源
    最近更新 更多