Welcome Guest, Not a member yet? Register   Sign In
accessing models
#1

[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.
#2

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

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

[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');
#4

[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...);
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB