報錯如下:
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,忘卻了許多事情。。。
新聞熱點
疑難解答