Welcome Guest, Not a member yet? Register   Sign In
DRY Base Controler
#1

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
Reply
#2

(This post was last modified: 10-05-2015, 04:10 PM by InsiteFX.)

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'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Thanks, that did the trick !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB