报错如下:
helloA php Error was encounteredSeverity: NoticeMessage: Undefined PRoperty: Test::$loadFilename: controllers/test.phpLine Number: 9Fatal error: Call to a member function view() on a non-object in D:\xampp\htdocs\citest\application\controllers\test.php on line 9
代码如下:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');class Test extends CI_Controller{public function test(){ //此处是引发错误的根源echo 'hello';}public function index(){$this->load->view('test/index');}public function about(){$this->load->view('test/about');}protected function test1(){echo 'test protected function';}private function hello(){echo 'hello,ci';}public function test2(){$this->test1();echo '<br/>';$this->hello();}}
看到哪里错了吗?因为我重写了test控制器的构造函数,这和类名一样的public方法和__construct方法是一样的功能的,重写了之后CI_Controller父类里的实例化什么的都没了,必须自己实例化了。
除了把和类同名的方法移除外,还有中方法如下:
public function test(){echo 'hello';parent::__construct();}public function index(){$this->load->view('test/index');}
这样就没问题了。
时隔三年,重新使用codeigniter,忘却了许多事情。。。