·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> CodeIgniter2.2.0-在控制器里调用load失败报错的问题

CodeIgniter2.2.0-在控制器里调用load失败报错的问题

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
CodeIgniter2.2.0-在控制器里调用load失败报错的问题

报错如下:

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,忘却了许多事情。。。