Hex 发表于 2015-1-14 10:26:52

11211042 发表于 2015-1-13 10:27
我是直接解压的最新的CI版本,在controllers中写了一个blog.php,代码和上面的一模一样,其他地方都没去 ...

贴代码。

11211042 发表于 2015-1-14 11:06:03

我就在controllers中建了一个blog.php,代码:
<?php

class Blog extends CI_Controller{
    public function _construct(){
      parent::_construct();
    }
    public function index(){
      echo "hello";
    }
}

?>

run blog.php提示:Fatal error: Class 'CI_Controller' not found in E:\wamp\www\Test\application\controllers\blog.php on line 3

但是我用http://localhost/Test/index.php/blog/去访问就能输出hello

Closer 发表于 2015-1-14 11:30:29

11211042 发表于 2015-1-14 11:06
我就在controllers中建了一个blog.php,代码:




public function _construct(){
  parent::_construct();
}

不是這樣寫?

function __construct(){
  parent::__construct();
}

 

11211042 发表于 2015-1-14 11:34:05

Closer 发表于 2015-1-14 11:30
public function _construct(){
  parent::_construct();
}


去掉public 还是提示一样的错误

Closer 发表于 2015-1-14 11:39:44

11211042 发表于 2015-1-14 11:34
去掉public 还是提示一样的错误

我主要想說的是兩個底線

11211042 发表于 2015-1-14 14:29:23

Closer 发表于 2015-1-14 11:39
我主要想說的是兩個底線


构造器是要加双下划线?
我试了双下划线还是不行
<?php

class Blog extends CI_Controller{
   /*
    public function _construct(){
      parent::_construct();
    }
   */

    public function index(){
      echo "hello";
    }
}

?>

我把构造器注释了,还是提示CI_Controller not found

Hex 发表于 2015-1-14 15:30:08

11211042 发表于 2015-1-14 14:29
构造器是要加双下划线?
我试了双下划线还是不行



我好像明白你的意思了,你用 http://localhost/Test/index.php/blog/ 这个可以访问,这是正确的访问方式。
你如果直接运行 blog.php 那肯定是不可以的,因为运行 CI 只能通过 index.php 运行,其他运行方式都是错误的,你可以理解为 CI 不支持其他方式运行。

11211042 发表于 2015-1-14 15:50:14

Hex 发表于 2015-1-14 15:30
我好像明白你的意思了,你用 http://localhost/Test/index.php/blog/ 这个可以访问,这是正确的访问方式 ...

是这个原因么?才学CI没多久,在写extends CI_Controller之前,不会pathinfo访问,我都是直接在代码段右键open in Browser访问的,那时候没出现问题。也就是说以后在controllers里extends CI_Controller后不能用右键访问了么?

Closer 发表于 2015-1-14 15:53:20

11211042 发表于 2015-1-14 15:50
是这个原因么?才学CI没多久,在写extends CI_Controller之前,不会pathinfo访问,我都是直接在代码段右 ...

不能在你的開發軟體右鍵開啟連結
除非他有套件是對應到 CI 的網址

11211042 发表于 2015-1-14 15:58:41

好的,又学到了
非常感谢两位帮忙!!
页: 1 [2] 3
查看完整版本: Class CI_Controller not found 什么情况...