Codeigniter & PHP - forcing a 404?

后端 未结 8 1348
予麋鹿
予麋鹿 2020-12-08 10:19

In codeigniter, as you know, a page of the form: /class/function/ID, where class is the controller name, function is the method within the controller, and ID is

相关标签:
8条回答
  • 2020-12-08 11:04

    try using this

    set_status_header(404);
    
    0 讨论(0)
  • 2020-12-08 11:06

    If you want a custom error page you can do the following thing.In your Libraries create a file name MY_Exceptions and extend it with CI_Exceptions.And then override the show_404() function.In this function you can now create an instance of your Controller class using &get_instance() function.And using this instance you can load your custom 404 Error page.

    class MY_Exceptions extends CI_Exceptions {
    
    public function __construct(){
        parent::__construct();
    }
    
    function show_404($page = ''){ // error page logic
    
        header("HTTP/1.1 404 Not Found");
        $heading = "404 Page Not Found";
        $message = "The page you requested was not found ";
        $CI =& get_instance();
        $CI->load->view('/*Name of you custom 404 error page.*/');
    
    }
    
    0 讨论(0)
提交回复
热议问题