Welcome Guest, Not a member yet? Register   Sign In
Passing instance objects between controller and model
#5

in order to prevent include_once calls we made a pre controller Hook which autoloads those classes 
and all classes are stored within a new folder called objects inside the application directory

PHP Code:
class AppAutoLoadObjects {

    private 
$arrObjectPaths = array(
        
'objects/',
        
'objects/core/'
    
);
            
    public function 
initialize()
    {
        
spl_autoload_register(array($this,'autoloadObjects'));
    }

    public function 
autoloadObjects($class)
    {
        if(
strpos($class'CI_') !== 0) {
            foreach(
$this->arrObjectPaths as $dir) {
                if (
file_exists(APPPATH.$dir.'/'.$class.'.php'))
                {
                    require_once(
APPPATH.$dir.'/'.$class.'.php');
                }
            }
        }
    }


and the hook in your hooks.php is very simple

PHP Code:
$hook['pre_system'][] = array(
    
'class' => 'AppAutoLoadObjects',
    
'function' => 'initialize',
    
'filename' => 'AppAutoLoadObjects.php',
    
'filepath' => 'hooks'
); 
Reply


Messages In This Thread
RE: Passing instance objects between controller and model - by sintakonte - 03-23-2016, 06:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB