Using the PHP spl_autoload_register() with Codeigniter to autoload my own classes |
[eluser]Ephyzy[/eluser]
I need to autoload my own classes in Codeigniter without rewriting them all as libraries (they are very many). Please how can I do this using spl_autoload_register()?
[eluser]OliverHR[/eluser]
If you write you code as oo i mean classes try using __autoload on config o register differents autoload functions there with spl_autoload_register(). Read this: CodeIgniter Base Classes: Keeping it DRY by Phil Sturgeon
[eluser]Ephyzy[/eluser]
Thanks, OliverHR. I already did that. I am using another framework which has its own autoload function called ___autoload_all. So I called spl_autoload_register("___autoload_all") right after it was defined. I still get the same errors. I think this may have something to do with CI's methods of autoloading, its not the conventional way. I was told that CodeIgniter has a different way of going about autoloading. Any help pls?
[eluser]Ephyzy[/eluser]
I am using the Flourish Unframework Library (http://flourishlib.com) and after speaking to the author, this was what he recommended. But I can't seem to find how to use spl_autoload_register() with CodeIgniter's own autoload.
[eluser]OliverHR[/eluser]
Codeigniter dont use __autoload because (until 1.7.2) its php 4 compatibility. Try next at the end of: Quote:application/config/config.php Code: function __autoload($class_name)
[eluser]Ephyzy[/eluser]
Thanks a lot, OliverHR. I tried that and it didnt work either! Thanks to http://ellislab.com/forums/viewthread/73804/#366081 and some bits of information from some CI folk that I follow on twitter (I asked em): [Eric Barnes], Dan Horrigan, Phil Sturgeon and Zack Kitzmiller, I found a solution. If you are a CodeIgniter n00b like me, you may like to follow these guys. I deleted init.php and config.php, then jammed the following into the bottom of my CI's config.php (I am also autoloading from a custom library called mylibrary). Code: function multi_auto_require($class) { Works brilliantly. Thanks, people!
[eluser]OliverHR[/eluser]
Good for you, I try the solution that I posted and works too. |
Welcome Guest, Not a member yet? Register Sign In |