Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Controller from executing

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...

like image 714
JonoB Avatar asked Jun 03 '26 01:06

JonoB


1 Answers

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();
like image 67
Broncha Avatar answered Jun 05 '26 15:06

Broncha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!