编辑用户配置文件后更新 Zend_Auth_Storage

发布于 2024-07-08 12:26:20 字数 389 浏览 6 评论 0原文

我有以下情况: 我已登录用户,使用数据库表进行标准身份验证

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

当用户编辑其配置文件时,我将其保存到数据库中,但我还需要更新存储(使用标准 Zend_Auth_Storage_Session)。 有什么简单的方法可以做到吗? 非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘曦 2024-07-15 12:26:20
$user = Zend_Auth::getInstance()->getIdentity();
$user->newValue = 'new value';

假设您在更新数据库的同一语句中更新会话数据,则无需再次调用数据库。

$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.

只等公子 2024-07-15 12:26:20

最好的选择是不要使用 Zend_Auth 的存储来保存可能更改的信息 - 默认情况下它只保存身份(有充分的理由)。 我可能会创建一个 User 类,其中包含所有 Auth、ACL(可能还有配置文件)功能,该功能使用静态 get_current() 方法来加载会话中隐藏的用户。 这绕过了将其填充到会话中时遇到的所有一致性问题,并且在您确实需要性能提升时为您提供了一个实施缓存的单点。

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.

没有伤那来痛 2024-07-15 12:26:20

我已经这样做了,它有效,但我不知道是否有更好的方法,如何做到这一点

$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);  

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);  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文