用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3308|回复: 5
收起左侧

[已解决] 找不到模型方法

[复制链接]
发表于 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
PHP复制代码
 
        function contactus(){
                  $this->load->helper('url');
                  $this->load->model('MContacts','',TRUE);
                  $this->MContacts->addContact();
                  redirect('welcome/thankyou','refresh');
        }
 
 
复制代码

模型页
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);
        }
复制代码
发表于 2010-3-13 22:15:31 | 显示全部楼层
太奇怪了,代码没问题。
load model 这里如果模型文件找不到会报错,楼主这里是对象没有 addContact 方法。
很奇怪,不知道谁遇到过。
发表于 2010-3-14 00:31:38 | 显示全部楼层
$this->load->model('MContacts','',TRUE);
var_dump($this->MContacts);
看看调试结果是什么
发表于 2010-3-14 09:38:11 | 显示全部楼层
你定义了一个对象和一个函数,应为多了一个'}'在函数定义之前

评分

参与人数 1威望 +1 收起 理由
Hex + 1 正解

查看全部评分

发表于 2010-3-14 10:52:52 | 显示全部楼层
哈哈,楼上正解!!
我竟然没看出来!
 楼主| 发表于 2010-3-14 17:47:43 | 显示全部楼层
非常感谢  ares333

本版积分规则