Kacper Kołodziej
Kacper Kołodziej

Reputation: 698

Zend_Db_Table_Row instance form Zend_Auth

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.

Upvotes: 0

Views: 257

Answers (2)

user430109
user430109

Reputation:

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;
    }
}

Upvotes: 1

mantigatos
mantigatos

Reputation: 296

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?

Upvotes: 1

Related Questions