如何使用 zend_auth 作为插件
我正在 Zend Framework 中进行第一次用户登录,但我对 Zend_Auth 有点困惑。我读到的所有关于它的文章都直接在控制器中使用它。但对我来说,作为插件更有意义 你们觉得怎么样?
I'm working on my first user login in Zend Framework, but I'm a little confused with Zend_Auth. All the articles I read about it use it directly in the controller. But to me, it makes more sense, to work as a plugin
What do you guys think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将它用作插件,唯一的缺点是,如果您在引导程序中初始化插件,则将为每个控制器和操作执行该插件,因为它必须在控制器之前运行。
您可以扩展 Zend_Auth 并添加额外的方法来设置身份验证适配器并管理存储,然后您可以调用 Your_Custom_Auth::getInstance() 来获取身份验证实例,然后您可以在 preDispatcth() 部分中检查身份验证您需要身份验证的控制器。
这样你就可以用更少的代码轻松地在多个地方使用 zend_auth
希望有帮助。
You can use it as a plugin, the only downside is that if you initialize the plugin in your bootstrap, then the plugin will be executed for every controller and action, since it would have to run before your controller.
You could extend Zend_Auth and add extra methods to set up the auth adapter and manage the storage, and then you can just call Your_Custom_Auth::getInstance() to get the auth instance and then you can check for auth in the preDispatcth() part of your controllers that need auth.
This way you can easily work with zend_auth in multiple places with less code
Hope that helps.
ZF 中的“插件”不仅意味着“前端控制器插件”,还意味着动作助手、视图助手...
ZF 大师 Matthew Weier O'Phinney 写了一篇关于创建动作助手的精彩文章,你猜怎么着?...
他举例说明了这一点带有 Auth 小部件!
http://weierophinney.net /matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html
不忘记阅读文章评论,因为那里处理了很多有趣的问答
"Plugin" in ZF doesn't only mean "front controller plugin", also Action helpers, view helpers...
ZF guru Matthew Weier O'Phinney wrote an excellent article about creating action helpers, and guess what ?..
He illustrates it with an Auth widget !
http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html
don't forget to read the articles comments, as a lot of interesting Q&A are handled there