[eluser]Dready[/eluser]
Hello,
that's really not a correct usage of helpers. I see two more elegant solutions :
Autoload your libraries with autoload functions
Perhaps you already know it, something like :
helpers/autoload_helper.php
Code:
function __autoload($class_name) {
if ( is_file(APPPATH.'/libraries/'.$class_name.'.php') ) {
require_once APPPATH.'/libraries/'.$class_name.'.php';
}
}
And in config/autoload.php
Code:
$autoload['helper'] = array('autoload');
Create a factory class
If you have many business classes, using a factory pattern can help you to have a common way to load all libraries.
libraries/factory.php
Code:
class factory {
function create($class_name,$your,$parameters) {
// security checks on $class_name here
...
require_once APPPATH.'/libraries/'.$class_name.'.php';
return new $class_name($your,$parameters);
}
}
in controllers :
Code:
$this->load->library('factory');
$myobject =& $this->factory->create('myObject','foo','bar');