Sunday, October 18, 2009

loading model in another model in CodeIgniter

Here I will show you how easy it is to load model inside another model in Codeigniter.

Say we have 2 models which are as follows:

class First_model extends Model
{
function First_model()
{
parent::Model();
}

function First_Function()
{
echo 'This is parent Function';
}
}

class Second_model extends Model
{
function Second_model()
{
parent::Model();

//Load First Model
$ci=& get_instance();
$ci->load->model('First_model');
}

function Second_Function()
{
//Call First model Function
$ci->First_model->First_Function();

}
}

You are Done.

1 comment:

  1. Thanks for your fine post.

    Using this way, Is it possible to call a controller function from another controller fucntion ?

    ReplyDelete