Using PHP interfaces in Codeigniter
Here's How to Get CodeIgniter to Load Interfaces Properly
In your application/config/autoload.php:
// Add "interface_autoloader" to your models array$autoload['model'] = array('interface_autoloader');
Now create a new class in your application/models folder "interface_autoloader.php":
<?phpclass Interface_autoloader { public function __construct() { $this->init_autoloader(); } private function init_autoloader(){ spl_autoload_register(function($classname){ if( strpos($classname,'interface') !== false ){ strtolower($classname); require('application/interfaces/'.$classname.'.php'); } }); }}
Now create a new folder in your application folder called "interfaces":
Then just add your interfaces into the "interfaces" folder and you should be able to use them like normal.
I'm using interfaces in my codeigniter project. I just do it:
Some classes need to extends a personal Controller, so I have created the librarie called Module_Controller extends Controller. This library is autoloaded.
In the same file, I have been declared the interface. So, my file libraries/Module_Controller.php has the following code:
class Module_Controller extends Controller{...}interface modular{...}
In this way, when this file be loaded, the interface will be declared for everyone.
You can create MY_Loader
class extends CI_Loader
into application/core and make load your interfaces.
Here has a sample: http://heatherevens.me.uk/2013/11/11/interfaces-in-codeigniter/