CodeIgniter Forums
DRY Base Controler - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: DRY Base Controler (/showthread.php?tid=63194)



DRY Base Controler - ComputingFroggy - 10-05-2015

Hi,

I am playing around with Ion Auth library.
I came across an article from Kyle Noland explaining how to set up base controller performing the identity check.
This was based on Phil Sturgeon article CodeIgniter Base Classes: Keeping it DRY.

It did not work for me: the Secure_Controller would not load, I was getting an error stating it wasn't found !
I had to move the Secure_Controller class declaration to the application/core/My_Controller.php file.

I believe using Base Controller is a fairly common setup: has anyone managed to get this working (without putting all the classes in the MY_Controller.php file) ?

(This is not an Ion Auth problem, this is a loading base controller problem).


Cheer,
L@u


RE: DRY Base Controler - InsiteFX - 10-05-2015

You need to add this autoloader to your ./application/config.php file:

PHP Code:
/*
| Autoloader function
|
| @author Brendan Rehman
| @param $class_name
| @return void
*/
function __autoloader($class_name)
{
    
// class directories
        
$directories = array(
            
APPPATH 'core/',
            
// add more autoloading folders here… and you’re done.
    
);

    
// for each directory
    
foreach ($directories as $directory)
    {
        
// see if the file exsists
        
if (file_exists($directory.$class_name '.php'))
        {
            require_once(
$directory.$class_name '.php');
            
// only require the class once, so quit after to save effort (if you got more, then name them something else

            
return;
        }
    }

}

spl_autoload_register('__autoloader'); 



RE: DRY Base Controler - ComputingFroggy - 10-08-2015

Thanks, that did the trick !