[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);
}
?>
...
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:
<?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
?>
cheers,
Frank