Updating Zend_Auth_Storage after edit users profile

痞子三分冷 提交于 2019-12-06 07:39:23

问题


I have following situation: I have loged user, standard authentication with DB table

$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter()); 
$authAdapter->setTableName('users'); 
$authAdapter->setIdentityColumn('user_name'); 
$authAdapter->setCredentialColumn('password'); 

When user edits his profile, I save it into Db, but I need to update also storage (using standard Zend_Auth_Storage_Session). Is there any easy way how to do it? Many thanks.


回答1:


Your best bet would be to not use Zend_Auth's storage to hold information that's likely to change - by default it only holds the identity (for good reason). I'd probably make a User class that wrapped all the Auth, ACL (and probably profile) functionality that uses a static get_current() method to load the user stashed in the session. This bypasses all the consistency issues you run into when stuffing it into the session as well as giving you a single point from which to implement caching if/when you actually need the performance boost.




回答2:


$user = Zend_Auth::getInstance()->getIdentity();
$user->newValue = 'new value';

Assuming you are updating the session data in the same statement you are updating the database in there is no need to call the db again.




回答3:


I have done it like this, it works, but I don't know if there is not some better way,how to do it

$user_data = User::getUser($user_id)->toArray();
unset($user_data['password']);

$std_user = new stdClass();

foreach ($user_data as $key => $value)
{
   $std_user->$key = $value;
}

$auth = Zend_Auth::getInstance();     
$auth->getStorage()->write($std_user);  


来源:https://stackoverflow.com/questions/304997/updating-zend-auth-storage-after-edit-users-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!