【问题标题】:404 index() function codeigniter404 index() 函数代码点火器
【发布时间】:2016-07-26 05:23:11
【问题描述】:

好吧,当我尝试访问时:

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';

【问题讨论】:

  • 您的控制器是否在子文件夹中?

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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2011-09-27
    • 2015-02-20
    • 1970-01-01
    • 2015-04-06
    • 2013-06-05
    • 2012-02-09
    • 2011-06-04
    • 2016-01-28
    • 2012-06-30
    相关资源
    最近更新 更多