Welcome Guest, Not a member yet? Register   Sign In
Load a Model within a Model
#1

[eluser]Unknown[/eluser]
Is it possible to load a model within a model?

For example, I have two models (Contact and Contact_Meta) and a controller (Admin).

Any help is appreciated.

Within Admin.php:

Code:
...
$this->load->model('contact');
$this->contact->delete_contact($contact_id);
...

Within Contact.php

Code:
...
function delete_contact ($contact_id)
{
  $this->load->model('contact_meta');
  $this->contact_meta->delete($contact_id); // fails here with the message: Undefined property: Contact::$contact_meta

  $this->db->where('contact_id',$contact_id);
  $this->db->delete('contact');
}
...

Within Contact_Meta.php

Code:
...
function delete_contact_meta ($contact_id)
{
  $this->db->where('contact_id',$contact_id);
  $this->db->delete('contact_meta');
}
...
#2

[eluser]wiredesignz[/eluser]
Try searching the forums for this topic, this question has been asked, and been answered, many times.




Theme © iAndrew 2016 - Forum software by © MyBB