CI_Controller Extension / Indirect Modification of Overloaded Property

The CI community does not seem to have an answer to this (or maybe it is so obvious that it looks like a noob question?), So I ask here.

I have seen this error for a long time (error messages follow), however I always used this "dirty" workaround . Now I no longer want to edit the main CI code, and I know that there must be an elegant solution for this.

Here is the setup.

In my application / config / routes I have this

$route['default_controller'] = "dispatcher"; 

The Dispatcher class in the application / controllers / is defined as follows:

 class Dispatcher extends MY_Controller { function __construct() { parent::__construct(); $this->load->helper(array('form','https')); } function index() { # load models $this->load->model('site/map'); $this->load->model('site/langs'); $this->load->model('site/pages'); if ( $mapped = $this->map->get_map() ){ // this is the line 21 $this->langs->set_user_lang( $this->GLO['show_lang_in_url'], $this->GLO['show_lang_at_home'] ); $red = base_url().$this->GLO['user_lang_label']."/".$mapped; redirect($red, "refresh"); } ... 

now MY_Controller is in the application / kernel and is defined as follows:

 class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); $this->GLO = array(); # # set defaults: # $this->GLO['deb'] = ''; $this->GLO['baseurl'] = base_url(); ... (more GLO[key] = value ) } public function __set ($key, $value ) { $this->GLO[$key] = $value; } 

Each model I use runs as follows (named accordingly):

 class Map extends CI_Model { function __construct(){ parent::__construct(); } function get_map(){ ..... return true; } 

Now that CI 2.1.2, PHP 5.3.3, Apache 2 on Debian when trying to load the page, I get this error:

A PHP error has occurred. Severity: Notification message: indirect change of the overloaded Langs :: $ GLO property does not affect File name: site / langs.php Line number: 82

A PHP error has occurred. Severity: Notification: Undefined Property: Dispatcher :: $ map File name: controllers / dispatcher.php Line Number: 21

Fatal error: call of get_map () member function for non-object in / home / webdev / MC / _WWW / application / controllers / dispatcher.php on line 21

Line 21 - the one noted above in the map model

 if ( $mapped = $this->map->get_map() ){ 

line 82 in another model is as follows:

 $this->GLO['langs'][] = $temp; 

Throughout the code, this GLO array references $ this-GLO [key]. He needs to be read and written from time to time. If I remove the __set function in MY_Controller, I get more of these warnings.

Where is the problem?

Many thanks!

+1
php continuous-integration codeigniter
source share
1 answer

I am not sure about the first error, but these two:

A PHP error has occurred. Severity: Notification: Undefined Property: Dispatcher :: $ map File name: controllers / dispatcher.php Line Number: 21

Fatal error: call of get_map () member function for non-object in / home / webdev / MC / _WWW / application / controllers / dispatcher.php on line 21

... it looks like you did not load your model correctly?

change

 if ( $mapped = $this->map->get_map() ){ 

to

 $this->load->model('map'); if ( $mapped = $this->map->get_map() ){ 
0
source share

All Articles