Welcome Guest, Not a member yet? Register   Sign In
model to model function calling?
#2

[eluser]gon[/eluser]
You must get a reference to CI object, this way:

Code:
$CI =& get_instance();

Then, $CI is just the same as $this when in controllers.

So you can do:

Code:
$CI->load->model('another_model');
$CI->another_model->whatever_method();

Usually you will want to store the reference into an instance property, so you can access it from any method of the model:

Code:
$this->CI =& get_instance();

That said, common utiliy functions are stored in libraries. So you can write a Utils library, and load it from the models:

Code:
class Example_model extends Model {
    function Example_model() {
        parent::Model();
        $this->CI =& get_instance();
        $this->load->library('utils');
    }

    function example_method() {
        $current_date = $this->CI->utils->get_nicely_formatted_date();
        .......
    }
}


Messages In This Thread
model to model function calling? - by El Forum - 08-19-2008, 12:03 PM
model to model function calling? - by El Forum - 08-19-2008, 01:35 PM
model to model function calling? - by El Forum - 08-19-2008, 02:04 PM
model to model function calling? - by El Forum - 08-19-2008, 02:45 PM
model to model function calling? - by El Forum - 08-19-2008, 03:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB