1

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!

4

2 回答 2

2

CI 的 url 格式描述:

domain.com/controller/method

并不是:

domain.com/method

如果您index function的控制器中有 a ,那么该函数将像这样调用:

domain.com
于 2013-09-09T09:26:23.473 回答
1

example.com/not_found/意思是,codeIgniter 会找到controllers/not_found.php并执行函数 index()

你必须创建控制器/not_found.php

于 2013-09-09T09:27:21.917 回答