Welcome Guest, Not a member yet? Register   Sign In
Load model in MY_Loader
#1

[eluser]John-Doe[/eluser]
How can I load a model in my MY_Loader.php -file in directory "application/core"?

Im trying to group my loader-views into a MY_Loader -file for more convenient loading of the views. I want to pass dynamic values to the header to customize the title output.

My code looks like this:

Code:
private $ci;  

public function __construct()
{
    parent::__construct();

    // Initiate instance
    $this->ci =& get_instance();

    // Load model
    $this->ci->load->model('My_loader_model');

}  

public function template($template_name, $vars = array(), $return = FALSE)
{
    $data_header['inbox_messages'] = $this->ci->My_loader_model->inbox_messages_count();

    $content  = $this->view('header', $data_header, $return);
    $content .= $this->view($template_name, $vars, $return);
    $content .= $this->view('footer', $vars, $return);

    if ($return)
    {
        return $content;
    }
}
#2

[eluser]CroNiX[/eluser]
Post the entire MY_Loader, including the definition.

it should be something like /application/core/MY_Loader.php:
Code:
class MY_Loader extends CI_Loader {
  //...rest of your code
}

I also wouldn't start your model name, or anything else, with "my_", unless you are directly extending a NATIVE CI class/library. That prefix has special meaning in CI. I'd just call it "loader_model" or something.




Theme © iAndrew 2016 - Forum software by © MyBB