404 index()函数codeigniter

时间:2016-04-06 02:29:47

标签: php codeigniter http-status-code-404

好吧,当我尝试访问:

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/$1';

1 个答案:

答案 0 :(得分:0)

routes.php中,在该行上方添加以下代码行:$route['(:any)'] = 'pages/view/$1';

$route['pages'] = 'pages';

如果这不起作用,请尝试对该行$route['(:any)'] = 'pages/view/$1';发表评论并检查网址:http://example.com/index.php/pages