• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using php5 __autoload function inside controllers classes to autoload models or libraries

#1
[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.

#2
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.