hellblog 发表于 2010-3-13 20:16:37

找不到模型方法

本帖最后由 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);
        }

Hex 发表于 2010-3-13 22:15:31

太奇怪了,代码没问题。
load model 这里如果模型文件找不到会报错,楼主这里是对象没有 addContact 方法。
很奇怪,不知道谁遇到过。

visvoy 发表于 2010-3-14 00:31:38

$this->load->model('MContacts','',TRUE);
var_dump($this->MContacts);
看看调试结果是什么

ares333 发表于 2010-3-14 09:38:11

你定义了一个对象和一个函数,应为多了一个'}'在函数定义之前

Hex 发表于 2010-3-14 10:52:52

哈哈,楼上正解!!
我竟然没看出来!

hellblog 发表于 2010-3-14 17:47:43

非常感谢ares333
页: [1]
查看完整版本: 找不到模型方法