找不到模型方法
本帖最后由 hellblog 于 2010-3-13 20:23 编辑Fatal error: Call to undefined method MContacts::addContact() in E:\php_study\ci\system\application\controllers\welcome.php on line 20
function contactus(){
$this->load->helper('url');
$this->load->model('MContacts','',TRUE);
$this->MContacts->addContact();
redirect('welcome/thankyou','refresh');
}
模型页
class MContactsextends 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);
} 太奇怪了,代码没问题。
load model 这里如果模型文件找不到会报错,楼主这里是对象没有 addContact 方法。
很奇怪,不知道谁遇到过。 $this->load->model('MContacts','',TRUE);
var_dump($this->MContacts);
看看调试结果是什么 你定义了一个对象和一个函数,应为多了一个'}'在函数定义之前 哈哈,楼上正解!!
我竟然没看出来! 非常感谢ares333
页:
[1]