Welcome Guest, Not a member yet? Register   Sign In
Automatically loading config and language files of the same name as controller
#4

[eluser]xwero[/eluser]
You can do it with hooks
Code:
// config/config.php
$config['enable_hooks'] = TRUE;
// config/hooks.php
$hook['post_controller_constructor'] = array(
                                'class'    => '',
                                'function' => 'autoload',
                                'filename' => 'post_controller_constructor.php',
                                'filepath' => 'hooks',
                                'params'   => array()
);
// hooks/post_controller_constructor.php
function autoload()
{
    $RTR =& load_class('Router');
    $class = $RTR->fetch_class();

    $CI =& get_instance();
    
    if(file_exists(APPPATH.'config/'.$class.EXT))
    {
       $CI->load->config($class);
    }

    if(file_exists(APPPATH.'language/'.config_item('language').'/'.$class.EXT))
    {
       $CI->load->lang($class);
    }
}
I don't know if it is working code but that should do it i think.

I rather work without hooks because i change the codeigniter.php file location in the index.php file so the original file is untouched.


Messages In This Thread
Automatically loading config and language files of the same name as controller - by El Forum - 08-11-2008, 07:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB