2012-03-10 13:12 阅读 46


I use Zend_Auth and Zend_Auth_Adapter_DbTable in my project. I want to get a Zend_Db_Table_Row instance from the Zend_Auth adapter (Zend_Auth_Adapter_DbTable). I haven't found any good solution. I need a Zend_Db_Table_Row instance because I use own row class in which I have a method to get data from dependent table.

I know that I can get this data once again but it makes no sense because this data was already fetched from the database by Zend_Auth_Adapter_DbTable.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douwei8672 douwei8672 2012-04-11 01:52

    The trick is putting the row into a Zend_Auth_Storage container. By overriding Zend_Auth_Adapter_Interface::authenticate(), you can do just that.

     * Authenticate
     * Overriding to provide more information about the authenticated user
     * @return Zend_Auth_Result
    public function authenticate()
        $result = parent::authenticate();
        //  Store row on success
        if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
            return new Zend_Auth_Result(
                $this->getResultRowObject(null, array('*')),
        } else {
            return $result;
    点赞 评论 复制链接分享
  • duansengcha9114 duansengcha9114 2012-03-10 18:49

    Zend_Auth_Adapter_DbTable fetches only those fields, which stored in users table (getResultRowObject()). I think it's more expedient is instancing your Row class (or User class) with data provided by Zend_Auth_Adapter_DbTable

    Look here for similar question: In Zend_Auth, can I get a domain-model User object instead of stdClass?

    点赞 评论 复制链接分享