php - Undefined $load property error after upgrading CodeIgniter 1.7 to 2.1 -
why error after upgrading codeigniter v1.7 v2.1?
a php error encountered severity: notice message: undefined property: site::$load filename: libraries/website.php line number: 25 fatal error: call member function library() on non-object in c:\xampp\htdocs\travel\application\libraries\website.php on line 25 the library application/library/website
class website extends ci_controller { public static $current_city; public function __construct() { $this->load->library('language'); // line 25 $this->language->loadlanguage(); $this->load_main_lang_file(); $this->load_visitor_geographical_data(); $this->load->library('bread_crumb'); } }
you forgot call __construct method of ci_controller class:
public function __construct() { // call ci_controller construct method first. parent::__construct(); $this->load->library('language'); // line 25 $this->language->loadlanguage(); $this->load_main_lang_file(); $this->load_visitor_geographical_data(); $this->load->library('bread_crumb'); } note: if you're creating controller, should placed in application/controllers/, not in application/libraries/.
if child (inheritor) class has constructor, parent constructor won't called, because you'll override parent's constructor child one, unless explicitly call parent's constructor using parent::__construct();. that's concept of polymorphism in object-oriented programming
if don't call parent::__construct(); when application controller initializing, you'll lose loader , core class , $this->load never works.
using parent::__construct(); needed if want declare __construct() method in controller override parent's one.
that's true models well, using parent::__construct(); in model logs debug message model class initialized, if need know when model initialized (in logs), keep using that, if not, ignore it.
Comments
Post a Comment