• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IBM tutorial model method call failure

#2
[eluser]Frank Berger[/eluser]
[quote author="fourcs" date="1224407841"]:coolmad: I'm using CI 1.6.3. Error logs tell me that there is a PHP fatal error: Call to undefined method MContacts::addContact() in controllers/welcome.php, line 23.

This is the model code, mcontacts.php:
Code:
<?php
class MContacts extends Model{

  function MContacts(){
    parent::Model();
  }
} // <------- look here

function addContact(){
  $now = date("Y-m-d H:i:s");
  $data = array(
    'name' => $this->input->xss_clean($this->input->post('name')),
    'email' => $this->input->xss_clean($this->input->post('email')),
    'notes' => $this->input->xss_clean($this->input->post('notes')),
    'ipaddress' => $this->input->ip_address(),
    'stamp' => $now
  );

  $this->db->insert('contacts', $data);
}

?&gt;
...
Any suggestions will be appreciated.[/quote]

The function addContact is not a member of your class Mcontacts, you close the class definition too soon. change it to this:

Code:
&lt;?php
class MContacts extends Model{

  function MContacts(){
    parent::Model();
  }


function addContact(){
  $now = date("Y-m-d H:i:s");
  $data = array(
    'name' => $this->input->xss_clean($this->input->post('name')),
    'email' => $this->input->xss_clean($this->input->post('email')),
    'notes' => $this->input->xss_clean($this->input->post('notes')),
    'ipaddress' => $this->input->ip_address(),
    'stamp' => $now
  );

  $this->db->insert('contacts', $data);
}
}  // <--- much better
?&gt;

cheers,
Frank


Messages In This Thread
IBM tutorial model method call failure - by El Forum - 10-18-2008, 10:17 PM
IBM tutorial model method call failure - by El Forum - 10-19-2008, 02:01 AM
IBM tutorial model method call failure - by El Forum - 10-19-2008, 05:38 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.