我正在使用PHP编写一个Web应用程序。我想为此使用MVC模式,并决定使用 CodeIgniter 。我的应用程序将有一些页面需要身份验证,一些页面不会。我想设计一个非常通用的方式,所以应该没有代码重复。可以任何一个指向一些好的设计/类结构为此?
I am writing a web application using PHP. I want to use the MVC pattern for this, and decided to go with CodeIgniter. My application will have some pages which will require authentication, and some pages won't. I want to design this in a very generic way, so that there should be no code duplication. Can any one point to some good "design/class structure" for this?
推荐答案写一个自定义库,你的代码igniter应用程序在每个页面视图。它应该具有以下功能:
Write a custom library that you can autoload in your code igniter app on every page view. It should have functions that:
- 验证用户ie。检查用户是否登录。
- 登录ie。
然后在您的控制器类中,您可以在构造函数中调用身份验证函数,然后根据结果继续正常,或将它们重定向到具有访问被拒绝消息的登录屏幕。
Then in your controller classes you can do a call to the authentication function in the constructor then depending on the outcome continue as normal or redirect them to a login screen with an access denied message.
执行搜索代码igniter wiki for'authentication',并且有一些结果可能有助于: codeigniter/ wiki /
Do a search on the code igniter wiki for 'authentication' and there are a number of results that may help: codeigniter/wiki/
更多推荐
使用CodeIgniter进行用户验证
发布评论