开发者

How do you exit execution of a codeigniter program?

I am currently working on adding pre-validation to my website. So that pages that require a log-in or other criteria, will only display if your session matches that criteria. I've got most of the system working, but I have one major obstacle. I cannot figure out how to stop CodeIgniter from running the rest of the controller (and thereby showing the page anyways), when the validation fails.

Here is my configuration:

  • All my pages are in the Content controller
  • My security system is a model called security.php
  • In the _head private function (which is called by every page), I load security.php and call it's main function: run()
  • $this->security->run() gets the specific validation criteria for the page, and checks them.

    • If the user passes, then run() does nothing, and the page execution continues

    • This is where I need help. If the user does not pass, then I need to display an开发者_如何学编程 error page, and stop the controller from calling any other views.

Does anyone know how to do this?

Thanks,

Lemiant


You could do one of two things. A would be to redirect to another page with a differant uri. B would be to use an if/else statement to choose which view you show under the same uri.

One thing you need to do is have the security method you talked about return TRUE or FALSE if it is successful or not.

Examples:

A:

if(!$this->security->run())
{
    redirect('my/error/page');
}

B:

if($this->security->run())
{
    // Security Passes, proceed as normal
}
else
{
    // Security Fails, show error page
}

Hope this helps


How stop execution of codeigniter: die(); or exit();

But, I don't think that's really what you want to do. What you want to do is to load a different view to show an error page if the validation fails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜