Welcome Guest, Not a member yet? Register   Sign In
Where to put plain object classes?
#37

I don't understand the debate. Maybe it is case of the framework getting in the way of thinking clearly Wink However, using the following code, I'm extending, overloading and whatever else like crazy. No include_once's anywhere, just a simple autoloader I added to config/config.php

Code:
/*
|--------------------------------------------------------------------------
| Auto-load models, controllers, libraries and more oh my
|--------------------------------------------------------------------------
*/

function application_autoloader($class) {
$locations = array(
APPPATH.'models'.DIRECTORY_SEPARATOR.strtolower($class).'.php',
APPPATH.'controllers'.DIRECTORY_SEPARATOR.ucfirst(strtolower($class)).'.php',
APPPATH.'libraries'.DIRECTORY_SEPARATOR.ucfirst(strtolower($class)).'.php',
APPPATH.'core'.DIRECTORY_SEPARATOR.strtolower($class).'.php',
);

foreach($locations as $location) :
if(file_exists($location)) :
include $location;
endif;
endforeach;
}
spl_autoload_register('application_autoloader');

function system_autoloader($class) {
$class = ucfirst(str_replace('CI_', '', $class)).'.php';

$locations = array(
BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$class,
BASEPATH.'core'.DIRECTORY_SEPARATOR.$class,
);

foreach($locations as $location) :
if(file_exists($location)) :
include $location;
endif;
endforeach;
}
spl_autoload_register('system_autoloader');
Reply


Messages In This Thread
Where to put plain object classes? - by geekita - 12-02-2014, 05:51 AM
RE: Where to put plain object classes? - by SomeGuy - 01-03-2015, 11:38 PM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 05:18 AM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 03:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB