Codeigniter显示404没有找到页面


Codeigniter shows 404 no page found.

我在我的Codeigniter页面有一个奇怪的问题。我有一个控制器类books.php

> <?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     function __construct() {
>         parent::__construct();
>     }
>     
>     
>     function main()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>

现在,如果我把浏览器指向http://localhost/CodeIgniter/index.php/books,它显示404 Page not found.现在,如果我在类声明上面添加一个echo 'Hello';,它显示hello,并在页面的顶部,在那行之后显示相同的404错误。这是因为权限问题吗?books.php777权限

> <?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     function __construct() {
>         parent::__construct();
>     }
>     
>     
>     function index()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>

访问时:

http://www.example.com/CodeIgniter/index.php/books

默认路由器实际上会加载

http://www.example.com/CodeIgniter/index.php/books/index

因此查找index方法。

尝试添加方法或调用您已定义的方法之一:

http://localhost/CodeIgniter/index.php/books/main
http://localhost/CodeIgniter/index.php/books/input

另外,您应该避免对您的文件拥有777权限。

您错过了index()功能。参考用户指南中的CodeIgniter url主题,了解更多关于基于分段的方法。

请在您的books.php中创建一个索引函数,或者只是为了测试,只需重命名主函数签名如下-

功能指数()

{
    $this->load->view('main_view');
}

请尝试以下代码

<?php
> //echo 'Hello';
> class Books extends CI_Controller{
>     public function index() {
>         echo "check";
>     }
>     
>     
>     function main()
>     {
>         $this->load->view('main_view');
>     }
>     
>     function input()
>     {
>         $this->load->view('input_view');
>     } } ?>