Codeigniter 底座控制器
让所有控制器以页面标识符作为参数重定向到站点的基本控制器,然后让基本控制器基于该参数周围的某些逻辑进行重定向,这是一个好的设计吗?
//base controller
function __construct($fromPage, $toPage) {
parent::__construct();
if($toPage == 'member_only') {
$this->is_logged_in();
}
}
function is_logged_in($controller) {
//redirect to appropriate controller from here?
}
关于基本控制器实践的一些建议会很棒:)
Is it a good design to have all controllers redirect to the site's base controller with a page identifier as the parameter, then having the base controller redirect based on some logic around that parameter?
//base controller
function __construct($fromPage, $toPage) {
parent::__construct();
if($toPage == 'member_only') {
$this->is_logged_in();
}
}
function is_logged_in($controller) {
//redirect to appropriate controller from here?
}
Some suggestions on base controller practice would be splendid :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,最好围绕模型构建控制器。
如果您有用户模型,请将其与用户控制器相匹配。并将所有与User模型相关的请求路由到对应的控制器(User)。与例如文章模型相同<->文章控制器等
编辑:要检查用户是否登录(或其他一些常见功能),请考虑 MY_Controller
In general, it is better to build your controllers around your models.
If you have a User model, match it with a User controller. And route all requests related to the User model to the corresponding controller (User). Same with, for example, Article model <-> Article Controller, etc.
Edit: For checking if the user is logged in (or some other common functionality), consider MY_Controller