I would like to be able to use OOP and create new objects in my controllers in CodeIgniter. So I need to use an autoload-function:
function __autoload( $classname )
{
require_once("../records/$classname.php");
}
But how can I add that to CodeIgniter?
You can add your auto loader above to app/config/config.php
. I've used a similar autoload
function before in this location and it's worked quite neatly.
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
@include_once(APPPATH . 'core/' . $class . EXT);
}
}
Courtesy of Phil Sturgeon. This way may be more portable. core
would probably be records
for you; but check your paths are correct regardless. This method also prevents any interference with loading CI_
libs (accidentally)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With