我使用Zend_Auth对用户进行身份验证,然后将其详细信息存储在默认的Zend_Auth会话中。这意味着当用户编辑其详细信息时,这些更改不会在应用程序中反映出来,直到他重新进行身份验证。
我希望避免这个问题的方法如下:
- When the user logs in we only store his
user ID
in aZend_Auth
session On each request we fetch the user's details from the database in a
preDispatch()
hook, using theuser ID
which was stored upon login in theZend_Auth
session:class Plugin_Auth extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { if ($auth->hasIdentity()) { $id = $auth->getIdentity()->id; $userModel = new Model_User(); $user = $userModel->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 theuser ID
must be persistent. Would storing theUser
object inZend_Registry
be an option here?