CodeIgniter Forums
accessing models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: accessing models (/showthread.php?tid=14799)



accessing models - El Forum - 01-15-2009

[eluser]Russell Keith[/eluser]
I am very confused. I have three models MRecords, MMail, and MUsers. From withing MRecords I can call my user function from MUsers to get the username, but I can't call my function from MMail to send a message I get the folloing error.

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined property: MRecords::$MMail

Filename: models/mrecords.php

Line Number: 353

Here is a section of the code that is causing me trouble.

Code:
class MRecords extends Model {
     function MRecords(){
          parent::Model();
     }
     function updateHRRecords($data,$user){
          $insert = array(
              'recordID' => $id,
              'denialNum' => $num,
              'denialReason' => $data['reason_'.$id],
              'denialUser' => $this->MUsers->getUserFullName($user,1)
          );
          $this->db->insert('denial_trail',$insert);
          $this->db->select('name,email');
          $this->db->where('id',$id);
          $Q = $this->db->get('record');
          $a = $Q->row();
          $Q->free_result();
          $this->MMail->denialEmail(boring variables...);
     }
}

Thanks in advance for any help.


accessing models - El Forum - 01-15-2009

[eluser]everdaniel[/eluser]
Well you should load the model you're going to use first (MMail):

Code:
$this->load->model('MMail');



accessing models - El Forum - 01-15-2009

[eluser]Russell Keith[/eluser]
I have it loaded in the autoload file. I can use it from the view or the controller just fine. I just can't use it from another model.

Code:
$autoload['model'] = array('MUsers','MPosting','MRecords','MLdap','MMail','MSettings','MAttachment');



accessing models - El Forum - 01-15-2009

[eluser]Colin Williams[/eluser]
It's always best, when outside of a controller, to use the get_instance() function and call other libs/models from it.

Code:
$ci =& get_instance();
$ci->MMail->denialEmail(boring variables...);



accessing models - El Forum - 01-15-2009

[eluser]Russell Keith[/eluser]
Perfect, thank you.