0

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 Answers 2

1

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(
            $result->getCode(),
            $this->getResultRowObject(null, array('*')),
            $result->getMessages()
        );
    } else {
        return $result;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.