You can also extend Zend_Auth like this:

class App_Auth extends Zend_Auth {

    protected $_user;

    public function getUser() 
    {
        if ( $this->hasIdentity() && !$this->_user ) {
              $table = new Model_DbTable_Users();
              $this->_user = $table->find( $this->getIdentity() )->current();
          } else {
              $this->_user = null;
          }
    }
}

And then you can use:

$user = null;
$auth = App_Auth::getInstance();
if ( $auth->hasIdentity() ) {
    ...
    $user = $auth->getUser();
} else {
    ...
}

Thomas

Il giorno 29/nov/2012, alle ore 00:41, monty <[email protected]> ha 
scritto:

> I use Zend_Auth to authenticate users and then store their details in the
> default Zend_Auth session. This means that when a user edits his details,
> these changes won't be reflected in the application until he
> re-authenticates.
> I want to avoid this problem as so:
> When the user logs in we only store his user ID in a Zend_Auth session
> On each request we fetch the user's details from the database in a
> preDispatch() hook, using the user ID which was stored upon login in the
> Zend_Auth session:
> class Plugin_Auth extends Zend_Controller_Plugin_Abstract{    public
> function preDispatch(Zend_Controller_Request_Abstract $request)    {       
> if ($auth-&gt;hasIdentity())        {            $id =
> $auth-&gt;getIdentity()-&gt;id;            $userModel = new Model_User();     
>       
> $user = $userModel-&gt;fetchOne($id);            // Where do I store this
> user object ???        }    }}
> The problem is: where do i store this User object? I think we shouldn't use
> sessions for this, since the goal of sessions is to persist data. There's no
> need for persistence though, since we re-fetch the data from the database on
> each request. Only the user ID must be persistent. Would storing the User
> object in Zend_Registry be an option here?
> 
> 
> 
> 
> --
> View this message in context: 
> http://zend-framework-community.634137.n4.nabble.com/Updating-Zend-Auth-storage-after-editing-user-details-tp4658269.html
> Sent from the Zend Framework mailing list archive at Nabble.com.


--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to