[英]default_controller route does not work with a function not_found in codeigniter
我已经在Codeigniter工作了很长时间。 我已将默认控制器设置为:
$route['default_controller'] = "main";
一切都很好,除非我在main.php
控制器文件中创建了一个函数,该函数可重定向到404 Not Found页面。
这是我在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);
}
然后,当我想加载example.com/not_found/
它会将我重定向到codeigniter的默认未找到页面,并说:
404 Page Not Found
The page you requested was not found.
但是,请求这样的页面没有问题:
example.com/main/not_found/
我是否需要设置其他路线,例如:
$route['not_found'] = "main/not_found";
?! 但这不是我想的好方法!
CI的url格式描述:
domain.com/controller/method
并不是:
domain.com/method
如果您的控制器中有一个index function
,则该函数将被这样调用:
domain.com
example.com/not_found/表示,codeIgniter将找到controllers / not_found.php并执行函数index()
您必须创建controllers / not_found.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.