![]() |
Extending CI_Loader - how to access CI Models? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Extending CI_Loader - how to access CI Models? (/showthread.php?tid=32448) |
Extending CI_Loader - how to access CI Models? - El Forum - 07-23-2010 [eluser]Sam Granger[/eluser] Hello! I want to extend the CI_Loader with MY_Loader. In MY_Loader, I want to access the CodeIgniter Agent Model. How can I achieve this? Thanks in advance! Extending CI_Loader - how to access CI Models? - El Forum - 07-23-2010 [eluser]WanWizard[/eluser] You can't do much in the loader, the class is loaded at a moment when CI isn't fully up and running, so things like 'get_instance()' won't work. I don't think MY_Loader is the place to put 'user' code, what is it exactly that you want to achieve? Extending CI_Loader - how to access CI Models? - El Forum - 07-23-2010 [eluser]Sam Granger[/eluser] I want visitors on mobile phones to see a different view "theme" - currently have a getTheme function in a Model named Theme. This function checks agent->is_mobile and from there it returns which folder the controller should load its views from ($this->load->view($this->theme->getTheme() . 'view_file')) I was wondering if I could just override the view function with this functionality - not sure what the best solution would be in this case? Extending CI_Loader - how to access CI Models? - El Forum - 07-23-2010 [eluser]WanWizard[/eluser] I don't think this is the way to go. I would rather opt to create two folders in the views directory, one for browser views, and one for mobile views. Then in your MY_Controller, do Code: define('VIEW_DIR', $this->theme->getTheme() ); // returns the name of the views directory, ending with a / Assuming that your MY_Controller loads and runs before you call your first view, you could use MY_Loader like this: Code: function view($view, $vars = array(), $return = FALSE) Then in your controllers you can keep using Code: $this->load->view('view_file'); which would load the view_file.php from the directory returned by getTheme(). Extending CI_Loader - how to access CI Models? - El Forum - 07-23-2010 [eluser]Sam Granger[/eluser] Nice, I'm already extending the Controller so it's a nice solution, will give it a try. Thanks! ![]() |