Extending CI_Controller / Indirect modification of overloaded property |
[eluser]popovich[/eluser]
Hello, I've been seeing this error for a long time now, however I have always used this "dirty" workaround. Now I do not want to edit the core CI code anymore, and I know there must be a graceful solution to this. In my application/config/routes I have this Code: $route['default_controller'] = "dispatcher"; The Dispatcher class in application/controllers/ is defined as this: Code: class Dispatcher extends MY_Controller { now MY_Controller resides in application/core and is defined as follows: Code: class MY_Controller extends CI_Controller { Every model I use starts like this (named accordingly): Code: class Map extends CI_Model { Now with CI 2.1.2, PHP 5.3.3, Apache 2 on Debian when trying to load a page, I am getting this error: Quote:A PHP Error was encountered The line 21 is the one marked above in the Map model Code: if ( $mapped = $this->map->get_map() ){ the line 82 in the other model looks like this: Code: $this->GLO['langs'][] = $temp; Throughout the code, this GLO array is referenced as $this-GLO[key]. It must be read and written from time to time. Where is the problem? Thanks a lot in advance!
[eluser]popovich[/eluser]
I know this might not be necessarily the problem of Codeigniter, but of PHP OOP syntax/logic – I just hope someone can help me with that here. How do you do that in your controllers/models?
[eluser]popovich[/eluser]
I should probably add that MY_Controller, which extends CI_Controller, has this __set function Code: public function __set ($key, $value ) { If I delete these lines, I get a longer list of "indirect modification of overloaded property" warnings. Still no clues?
[eluser]popovich[/eluser]
Ok, here is a more simple question: within CI framework, how do you properly define a variable (array) which is available from any model, library, helper, etc? PS. It is weird to be talking to myself...
[eluser]Abdul Malik Ikhsan[/eluser]
try this : Code: $ci = & get_instance();
[eluser]popovich[/eluser]
OK, this works. In MY_Controller at the end of __constructor: Code: $CI =& get_instance(); In Dispatcher class (which extends MY_Controller): Code: print_r($this->testing); the output is as expected. However the override error persists. O_o
[eluser]Abdul Malik Ikhsan[/eluser]
not like that, for example like this : Code: class MY_Controller extends CI_Controller Code: class Dispatcher extends MY_Controller
[eluser]popovich[/eluser]
The "testing" array can be read alright – as it was the case before. However it still cannot be modified from within loaded models.
[eluser]Abdul Malik Ikhsan[/eluser]
it can. place $this->load->model('yourmodel') after parent::__construct() Code: class Dispatcher extends MY_Controller Code: class yourmodel
[eluser]popovich[/eluser]
Thanks for bearing with me. But isn't this method just setting testing[key] within a newly created instance only? I guess so, cause even though I have got rid of errors, the original testing array was not modified – it was probably modified only within the model and the new values are still not available within the Dispatcher class. ![]() |
Welcome Guest, Not a member yet? Register Sign In |