[英]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://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.