编辑用户配置文件后更新 Zend_Auth_Storage
我有以下情况: 我已登录用户,使用数据库表进行标准身份验证
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您在更新数据库的同一语句中更新会话数据,则无需再次调用数据库。
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.
最好的选择是不要使用 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.
我已经这样做了,它有效,但我不知道是否有更好的方法,如何做到这一点
I have done it like this, it works, but I don't know if there is not some better way,how to do it