CodeIgniter 2.0 Fatal error: Call to undefined method CI_Controller::CI_Controller() in D:xampphtdocsCodeIgniterapplicationcoreMY_Controller.php on line 10

今日嘗試在Codengiter
寫一個override class去 replace 原有的 Controller Class 時出現了這個錯誤…

Call to undefined method CI_Controller::CI_Controller()
Fatal error: Call to undefined method CI_Controller::CI_Controller() in D:xampphtdocsCodeIgniterapplicationcoreMY_Controller.php on line 10

我已經檢查了…我這個Override class [My_Controller] 已經放中了正確的資料來內…
D:xampphtdocsCodeIgniterapplicationcoreMY_Controller.php

最後發現原來我忘了 overload __construct 這個method…加了以下的code 便可…

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

在這個Class 入面的Code 變成了

<?php
class MY_Controller extends CI_Controller {

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

	function MY_Controller()
	{
		parent::CI_Controller();

	}
}

Hope you find it useful

5 thoughts on “CodeIgniter 2.0 Fatal error: Call to undefined method CI_Controller::CI_Controller() in D:xampphtdocsCodeIgniterapplicationcoreMY_Controller.php on line 10

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.