![]() |
Using php5 __autoload function inside controllers classes to autoload models or libraries - 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: Using php5 __autoload function inside controllers classes to autoload models or libraries (/showthread.php?tid=14041) |
Using php5 __autoload function inside controllers classes to autoload models or libraries - El Forum - 12-16-2008 [eluser]Isos[/eluser] Hi! It's an idea that I just got but I am not able to find the proper way to implement this! I was told that __autoload can be a function part of a class to auto load classes whenever they are defined within the the class. In my case, I want to use it inside the controller (or the common controller from which all controllers extend as i have in my script) to autoload models and libraries instead of doing that in every controller. Now about the codeigniter's autoload, I think it does not function the way __autoload does where I guess the CI autoloads everything everywhere as having includes in everypage whether the page will use the contents of the includes or not, but php5's __autoload will do that where needed. So I am just giving the idea and asking if anyone succeeded (or will adopt the idea and will succeed) in having this work properly. I will keep working to find the best way and will keep you updated with whatever comes up with me or whatever I may find. Thanks. Using php5 __autoload function inside controllers classes to autoload models or libraries - El Forum - 12-16-2008 [eluser]xwero[/eluser] If you look at Kohanas code they assign an auto_load function using the spl_autoload_register function in their front controller. In CI the autoloading method is executed when you initialize the controller. So what you can do is to replace the [code]$this->load->_ci_autoloader();[code] with the spl_autoload_register function. That would do the trick i guess. |