这是我的控制器类
public function _construct()
{
parent::_construct();
$this->load->model('customer_model');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Title', 'required');
$this->form_validation->set_rules('address', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->helper('url');
$this->load->view('templates/header');
$this->load->view('master/customer');
}
else
{
$this->customer_model->register();
//$this->load->view('news/success');
}
} }
这是我的模型课
类Customer_model扩展了CI_model {
public function _construct()
{
$this->load->database();
}
public function register()
{
$data = array(
'name' => $this->input->post('name'),
'address' => $this->input->post('address')
);
return $this->db->insert('registration', $data);
}
}
在运行codeigniter时我收到此错误
遇到PHP错误
严重性:注意
消息:未定义的属性:Customer :: $ customer_model
文件名:controllers / customer.php
行号:30
致命错误:在第30行的C:\ xampp \ htdocs \ CodeIgniter_2.1.3 \ application \ controllers \ customer.php中的非对象上调用成员函数register()
我是新的代码签名任何正文,请告诉我为什么会出现这个错误
答案 0 :(得分:0)
在控制器&模特,试着改变:
public function _construct() {
....
}
到
public function __construct() { //double underscore
....
}