找不到方法
Fatal error: Call to undefined method Mcontacts::addContact() in E:\php_study\ci\system\application\controllers\welcome.php on line 20控制页welcome.php
function contactus(){
$this->load->helper('url');
$this->load->model('Mcontacts','',TRUE);
$this->Mcontacts->addContact();
redirect('welcome/thankyou','refresh');
}
模型页mcontacts.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);
}
为什么找不到呢 剖析模型
模型类文件存放在 application/models/ 文件夹。 如果你愿意,可以在里面建立子文件夹。
最基本的模型类必须像这样:class Model_name extends Model {
function Model_name()
{
parent::Model();
}
}
Model_name 是模型类的名字。 类名的首字母必须大写,其他字母小写。并且确保你的类继承了基本模型类(Base Model Class)。
文件名应该是模型类名的小写版。比如,如果你的类是:class User_model extends Model {
function User_model()
{
parent::Model();
}
}
类的文件名应该是:application/models/user_model.php
页:
[1]