the simple way is using config/autoload.php file. put your code as a library, and make it autoload.
but if you are gonna have lots of classes you wanna import, it's not a practical approach. here is what i did:
i made a folder specifically for my own files and libraries, namespaced it, and made it autoload.
now let's say you put your files in MyProject folder and namespaces are matched with paths. like MyProject/Bases/Class1.php has namespace MyProject/Bases.
then you add this code at the end of your config/config.php file.
spl_autoload_extensions('.php'); // Only Autoload PHP Files
spl_autoload_register(function($classname){
if( strpos($classname,'\\') !== false ){
// Namespaced Classes
$classfile = /*strtolower(*/str_replace('\\','/',$classname)/*)*/;
if($classname[0] !== '/'){
$classfile = APPPATH.''.$classfile.'.php';
}
require($classfile);
} else if( strpos($classname,'interface') !== false ){
// Interfaces
strtolower($classname);
require('application/interfaces/'.$classname.'.php');
}
});
this piece of code auto loads all the files namespaced in the application directory. now you can add any file you want, namespace it according to its directory path, and 'use' it in your classes.
thanks Thimothy Perez for his answer here