![]() |
how to retrieve a post_controller_constructor variable in models? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how to retrieve a post_controller_constructor variable in models? (/showthread.php?tid=37054) |
how to retrieve a post_controller_constructor variable in models? - El Forum - 12-25-2010 [eluser]Unknown[/eluser] I set value to a language related variable (actually a property) in post_controller_constructor this way: Code: $ci =& get_instance(); I can retrieve this variable in views: $this->lngcode, but it is not possible in models, as $this->lngcode throws an error here. Unfortunately, i need this value in a model. I am relatively new to CI so my first question is: why $this->lngcode is wrong here in the model? Is it OK (a good practice?) to retrieve this variable by referencing the CI superobject in the model (i tested and it works): Code: $ci =& get_instance(); or should i pass this value in the controller as a parameter to the model's method? Thx for help! how to retrieve a post_controller_constructor variable in models? - El Forum - 12-25-2010 [eluser]jedd[/eluser] Hi teamtom and welcome to the CI forums. I understand that in general terms you should avoid using get_instance like this - from memory it's a (relatively) expensive operation. You might want to look at using [url="/user_guide/libraries/sessions.html"]Session data[/url] for storing this kind of stuff - especially if it is something that will change based on different user's preferences. how to retrieve a post_controller_constructor variable in models? - El Forum - 12-26-2010 [eluser]Unknown[/eluser] hi jedd, thanks for the answer! i am familiar with the concept of the session in this case i tried NOT to use anything related to cookies to build a SEO friendly multi language site with langcode (en, de, fr, etc.) in the url thinking of KISS (keep it simple stupid), you are right, a session variable seems good enough for the job but what about the first question? why does $this->lngcode throw an error in a model? TIA, teamtom |