简体   繁体   English

Codeigniter显示404找不到页面。

[英]Codeigniter shows 404 no page found.

Well I have a strange problem in my Codeigniter page. 好吧,我在Codeigniter页面中遇到一个奇怪的问题。 I have a controller class books.php 我有一个控制器类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');
>     } } ?>

Now if I point my browser to http://localhost/CodeIgniter/index.php/books it shows 404 Page not found. 现在,如果我将浏览器指向http://localhost/CodeIgniter/index.php/books则会显示404 Page not found. Now If I add a echo 'Hello'; 现在,如果我添加echo 'Hello'; just above the class declaration, it shows hello and at the top of the page and after that line the same 404 error.Is this due to permission roblem. 在类声明的上方,它会在页面顶部和该行之后显示hello,并在该行之后显示相同的404错误,这是由于权限问题引起的。 books.php have 777 permission. books.php具有777权限。

> <?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');
>     } } ?>

When accessing: 访问时:

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

the default router will actually load up 默认路由器将实际加载

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

It is therefore looking for the index method. 因此,它正在寻找索引方法。

Try adding the method or calling either of the method that you have defined: 尝试添加方法或调用已定义的方法之一:

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

Also, you should refrain from having 777 permissions on your files. 同样,您应该避免对文件具有777权限。

You are missing the index() function. 您缺少index()函数。 Refer to CodeIgniter URLs topic in their user guide to find out more about their segment-based approach. 请参阅其用户指南中的CodeIgniter URL主题,以了解有关基于段的方法的更多信息。

Please create a index function inside your books.php or just for a sake of test just rename main function signature as follows - 请在您的books.php中创建一个索引函数,或者只是为了进行测试,只需按如下所示重命名主函数签名-

function index() 函数index()

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

Please try with following code 请尝试以下代码

<?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');
>     } } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM