簡體   English   中英

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

訪問時:

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

默認路由器將實際加載

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

因此,它正在尋找索引方法。

嘗試添加方法或調用已定義的方法之一:

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

同樣,您應該避免對文件具有777權限。

您缺少index()函數。 請參閱其用戶指南中的CodeIgniter URL主題,以了解有關基於段的方法的更多信息。

請在您的books.php中創建一個索引函數,或者只是為了進行測試,只需按如下所示重命名主函數簽名-

函數index()

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM