防止控制器执行 [英] Prevent Controller from executing

查看:142
本文介绍了防止控制器执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在MY_Controller中运行的acl。如果权限被拒绝,那么在这一刻,我只是做一个 redirect('denied') - 这是一个非常基本的控制器加载一个非常基本的视图,说Permission denied '。



但是,我想要做的是,仍然加载最初请求的uri,但加载denied视图而不是默认视图。 p>

我可以在MY_Controller中做到这一点,被拒绝的视图加载正常。但是,这不会停止原来的控制器/方法执行,所以我得到两个视图加载。我也试着在加载被拒绝的视图后在MY_Controller中放一个退出; 语句,但是这不可行,因为输出不会在CI中触发。



是否可能通过pre_constructor_controller钩子来做到这一点?我不知道如何防止控制器执行...

解决方案



在检查 MY_Controller 中的ACL之后,如果不允许,您可以加载拒绝视图,但是您需要在退出之前再做一件事。

  $ this-> load-> view('denied'); 
$ this-> output-> _display()?
exit();


I have an acl that is running in MY_Controller. If permission is denied, then at the moment, I just do a redirect('denied') - this is a very basic controller that loads a very basic view saying 'Permission denied'.

However, what I would like to do instead, is still load the originally requested uri, but load the 'denied' view instead of the default view.

I can do this in MY_Controller, and the denied view loads fine. However, this does not stop the original controller/method from executing as well, so I get both views loaded. I also tried putting an exit; statement in MY_Controller after loading the denied view, but this is not workable because then the output does not fire in CI.

Is it perhaps possible to do this via a pre_constructor_controller hook? I couldn't figure out a way to prevent the controller from executing...

解决方案

You have to let the controller execute in order to let the requested URI load.

After you check the ACL in MY_Controller and if it is not permitted, you can load the denied view there, but you need to do one more thing before you exit.

$this->load->view('denied');
$this->output->_display();
exit();

这篇关于防止控制器执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆