404 index() 函数代码点火器
404 index() function codeigniter
好吧,当我尝试访问:
http://example.com/index.php/pages/index
我没有问题,但是当我尝试使用时:
http://example.com/index.php/pages
我有一个 404 错误。
我的控制器代码:
<?php
class Pages extends CI_Controller {
public function index(){
echo "index page";
}
public function view($page = 'home'){
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')){
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>
我的路线配置:
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/';
在您的 routes.php
行上方添加以下代码行:$route['(:any)'] = 'pages/view/';
$route['pages'] = 'pages';
如果这不起作用,请尝试注释行 $route['(:any)'] = 'pages/view/';
并检查 url:http://example.com/index.php/pages
好吧,当我尝试访问:
http://example.com/index.php/pages/index
我没有问题,但是当我尝试使用时:
http://example.com/index.php/pages
我有一个 404 错误。
我的控制器代码:
<?php
class Pages extends CI_Controller {
public function index(){
echo "index page";
}
public function view($page = 'home'){
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')){
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>
我的路线配置:
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/';
在您的 routes.php
行上方添加以下代码行:$route['(:any)'] = 'pages/view/';
$route['pages'] = 'pages';
如果这不起作用,请尝试注释行 $route['(:any)'] = 'pages/view/';
并检查 url:http://example.com/index.php/pages