zend-framework - Zend session 和 Zend 身份验证

标签 zend-framework zend-auth zend-session

我已经通过 Zend auth 创建了一个登录系统,这里是代码

// userAuthentication
   public function authAction(){
       $request     = $this->getRequest();
       $registry    = Zend_Registry::getInstance();
       $auth        = Zend_Auth::getInstance(); 
       $DB = $registry['DB'];
           $authAdapter = new Zend_Auth_Adapter_DbTable($DB);
               $authAdapter->setTableName('user')
                            ->setIdentityColumn('user_name')
                            ->setCredentialColumn('user_password');

      $username = $request->getParam('username');
      $password = $request->getParam('password');
      $authAdapter->setIdentity($username);
      $authAdapter->setCredential($password);
      $result = $auth->authenticate($authAdapter);

      if($result->isValid()){
           $data = $authAdapter->getResultRowObject(null,'password');
           $auth->getStorage()->write($data);
           $this->_redirect('/login/controlpannel');
       }else{
           $this->_redirect('/login/login');
        }
  }

现在这个工作正常。用户(表)中有 user_id(列),其中也有用户名和密码。我需要从这个表中获取特定的 user_id,它只是登录并将其放入 session 中
$user_session = new Zend_Session_Namespace('user_session');
$user_session->username = $username;
$user_id->user_id       = $user_id;

这样我就可以针对这个 $user_id 查询一些信息并将结果传递到 View (名称)控制面板

最佳答案

从存储中获取用户 ID:

$userInfo = Zend_Auth::getInstance()->getStorage()->read();

echo $userInfo->user_id;

关于zend-framework - Zend session 和 Zend 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9001847/

相关文章:

php - 如何在没有 SQL 查询的情况下使用 Zend_Db?

linux - 通过 cron 执行脚本时使用 Zend Lucene 的 PHP iconv 错误,但不在命令行上

zend-framework2 - Zend Framework 2 - 身份验证/ACL

zend-framework - Zend 框架 : How to check an additional column while using DbTable Auth Adapter?

zend-framework - Zend Session Handler Db 表在 PHPUnit 测试期间被破坏

php - 当使用 Zend_Config_Ini 时,如何指定相对于配置文件位置的文件路径?

php - zend paginator 最终是否使用 LIMIT OFFSET

php - Zend 导航 : Where should I load the ACL 'Role' in a private application

php - 在 zf1 , zf2 项目中使用相同的 session