简体   繁体   中英

default_controller route does not work with a function not_found in codeigniter

I have been working with codeigniter for a long time. I have set my default controller to:

$route['default_controller'] = "main";

everything is fine, except I have created a function in main.php controller file that redirects to 404 Not Found page.

This is my code in main.php:

function not_found()
{
    $data['page_Title'] = '404 Error!';
    $data['page_Description'] = 'Description';
    $data['page_Keywords'] = 'Keywords';
$data['main_content'] = 'not_found';
    $this->load->view('includes/template', $data); 
}

Then when I want to load example.com/not_found/ it redirects me to the codeigniter's default not found page and says:

404 Page Not Found

The page you requested was not found.

but, there is no problem requesting the page like:

example.com/main/not_found/

Do I have to set another route like:

$route['not_found'] = "main/not_found";

?! but this is not a good way I think!

The url format of CI describes :

domain.com/controller/method

And not:

domain.com/method

If you have a index function in your controller then that function will be called like this:

domain.com

example.com/not_found/ mean, codeIgniter will find controllers/not_found.php and execute function index()

You have to create controllers/not_found.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM