title: Why is CodeIgniter producing "Call to undefined method" in model I've created?
body: <p>So I've been tasked with creating a function for our member database that will alert someone on a monthly basis as to when their membership is going to expire.  We send out one email if a person is 6 months or less from their membership expiration, and another if they are 3 months out.  No big whoop.  I first create a model like this:</p>
  
  <pre><code>class Email extends CI_Model {
  
  function __construct()
  {
      parent::__construct();
  }
  
  // -----------------EMAIL-----------------
  function emailMessage($message = 1,$recipient = 1777) { // Default "Test" Numbers
      $rInfo = $this-&gt;db-&gt;query("SELECT * FROM Members WHERE intKey = " . $recipient)-&gt;row();
      $eInfo = $this-&gt;db-&gt;query("SELECT * FROM Emails WHERE intKey = " . $message)-&gt;row(); 
  
      // Replacements?
      $bodyCopy = $eInfo-&gt;txtEmail;
      $bodyCopy = str_replace("[firstname]",$rInfo-&gt;strFirstName,$bodyCopy);  
  
      $this-&gt;load-&gt;library('email');
      $this-&gt;email-&gt;from('someone@example.com','John Q Public');
      $this-&gt;email-&gt;to($rInfo-&gt;strEmail); 
      $this-&gt;email-&gt;subject($eInfo-&gt;strTitle);
      $this-&gt;email-&gt;message($bodyCopy);
      $this-&gt;email-&gt;send();
      $this-&gt;email-&gt;clear();
  }
  }
  </code></pre>
  
  <p>All fine and good, and when I call this model from any other part of the site I have built, it works fine.  It's a great way to handle any stock emails that have to be sent out to our constituency.  Normally, it's just something like this within the code:</p>
  
  <pre><code>$this-&gt;load-&gt;model('email');
  $this-&gt;email-&gt;emailMessage(8,$this-&gt;session-&gt;userdata('memberKey'));
  </code></pre>
  
  <p>Works like a charm.  The big difference between where I've used it previously, and where I use it now is that I'm enclosing the call to the model within a loop as follows:</p>
  
  <pre><code>public function warningEmails() {
      $this-&gt;load-&gt;model('email');
      $sql = 'SELECT
                  *, FLOOR(
                      DATEDIFF(dtAccreditationEnd, now())/ 30
                  )AS diff
              FROM
                  tblMembers
              WHERE
                  enmAccredited = "yes"
              AND dtAccreditationEnd &lt; DATE_ADD(now(), INTERVAL 6 MONTH)
              ORDER BY
                  diff
      ';  
      $emailSend = $this-&gt;db-&gt;query($sql);
      foreach ($emailSend-&gt;result() as $row) {
          if ($row-&gt;diff &lt;= 3) {
              $letter = 10;
          } else {
              $letter = 9;
          }
          $this-&gt;email-&gt;emailMessage($letter,$row-&gt;intMembersKey);
      }
  }
  </code></pre>
  
  <p>It works great the first time through the loop, and fails with the following message the very next iteration through the loop:</p>
  
  <p><strong>Fatal error</strong>: Call to undefined method CI_Email::emailMessage() in <strong>/home/contract/public_html/members/application/controllers/staff.php</strong> on line <strong>1033</strong></p>
  
  <p>Line 1033 is this line:</p>
  
  <pre><code>  $this-&gt;email-&gt;emailMessage($letter,$row-&gt;intMembersKey);
  </code></pre>
  
  <p>I there a problem where this model can only be called once in a given instance?  What am I doing wrong?  Thank you in advance for your assistance!</p>
  
  <p><strong>EDIT:</strong> I'm going to add a var_dump($this->email); to see what it could be...</p>
  
  <blockquote>
    <p>object(CI_Email)#30 (46) {   ["useragent"]=>   string(11)
    "CodeIgniter"   ["mailpath"]=>   string(18) "/usr/sbin/sendmail"<br>
    ["protocol"]=>   string(4) "mail"   ["smtp_host"]=>   string(0) ""<br>
    ["smtp_user"]=>   string(0) ""   ["smtp_pass"]=>   string(0) ""<br>
    ["smtp_port"]=>   string(2) "25"   ["smtp_timeout"]=>   int(5)<br>
    ["smtp_crypto"]=>   string(0) ""   ["wordwrap"]=>   bool(true)<br>
    ["wrapchars"]=>   string(2) "76"   ["mailtype"]=>   string(4) "text"<br>
    ["charset"]=>   string(5) "utf-8"   ["multipart"]=>   string(5)
    "mixed"   ["alt_message"]=>   string(0) ""   ["validate"]=><br>
    bool(false)   ["priority"]=>   string(1) "3"   ["newline"]=><br>
    string(1) " "   ["crlf"]=>   string(1) " "   ["send_multipart"]=><br>
    bool(true)   ["bcc_batch_mode"]=>   bool(false)   ["bcc_batch_size"]=>
    int(200)   ["_safe_mode"]=>   bool(false)   ["_subject"]=>   string(0)
    ""   ["_body"]=>   string(357) "Geoffrey,</p>
    
    <p>This is a reminder that your PDCA Accreditation will expire in 3
    months.   Visit your Membership Dashboard to view all complete and
    incomplete course work at your convenience. The Membership Dashboard
    will assist you through the completion process.     For more
    information, please contact Someone at Someone@example.com or
    1-800-555-1212."   ["_finalbody"]=>   string(0) ""<br>
    ["_alt_boundary"]=>   string(0) ""   ["_atc_boundary"]=>   string(0)
    ""   ["_header_str"]=>   string(0) ""   ["_smtp_connect"]=><br>
    string(0) ""   ["_encoding"]=>   string(4) "8bit"   ["_IP"]=><br>
    bool(false)   ["_smtp_auth"]=>   bool(false)   ["_replyto_flag"]=><br>
    bool(false)   ["_debug_msg"]=>   array(0) {   }   ["_recipients"]=><br>
    string(17) "recipient@example.com"   ["_cc_array"]=>   array(0) {   } 
    ["_bcc_array"]=>   array(0) {   }   ["_headers"]=>   array(5) {
        ["From"]=>
        string(54) ""Someone Example" "
        ["Return-Path"]=>
        string(28) ""
        ["Cc"]=>
        string(16) "copy@example.com"
        ["Bcc"]=>
        string(17) "blindcopy@example.com"
        ["Subject"]=>
        string(49) "=?utf-8?Q?PDCA_Accreditation_Expiration_Warning?="   }   ["_attach_name"]=>   array(0) {   }   ["_attach_type"]=>   array(0) { 
    }   ["_attach_disp"]=>   array(0) {   }   ["_protocols"]=>   array(3)
    {
        [0]=>
        string(4) "mail"
        [1]=>
        string(8) "sendmail"
        [2]=>
        string(4) "smtp"   }   ["_base_charsets"]=>   array(2) {
        [0]=>
        string(8) "us-ascii"
        [1]=>
        string(9) "iso-2022-"   }   ["_bit_depths"]=>   array(2) {
        [0]=>
        string(4) "7bit"
        [1]=>
        string(4) "8bit"   }   ["_priorities"]=>   array(5) {
        [0]=>
        string(11) "1 (Highest)"
        [1]=>
        string(8) "2 (High)"
        [2]=>
        string(10) "3 (Normal)"
        [3]=>
        string(7) "4 (Low)"
        [4]=>
        string(10) "5 (Lowest)"   } }</p>
  </blockquote>