【发布时间】:2016-10-13 16:31:09
【问题描述】:
我正在使用 CodeIgniters form_validation 库来验证我的应用程序中的表单。此处加载的库:
$autoload['libraries'] = array('database','form_validation');
自从包含库以来,我无法在应用程序中加载任何模型。我在浏览器中收到以下错误。该表格是用户注册网站的注册表单。表单得到完美验证。
A PHP Error was encountered
Severity: Notice
Message: Undefined property: register_model::$load
Filename: libraries/Form_validation.php
Line Number: 147
这是我尝试加载模型的函数:
public function validateRegForm(){
$this->load->model('register_model');
$this->load->helper('url');
$this->load->helper('form');
$this->form_validation->set_rules('firstname', 'First Name', 'required');
$this->form_validation->set_rules('lastname', 'Last Name', 'required');
$this->form_validation->set_rules('address', 'Address', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('phone', 'Phone', 'required');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirm-password', 'Confirm Password', 'required|matches[password]');
if ($this->form_validation->run() == FALSE){
$data['title'] = 'Sign Up';
$this->load->view('template/header', $data);
$this->load->view('template/navigation');
$this->load->view('register_view');
$this->load->view('template/footer');
} else {
$data = array(
'firstName' => $this->input->post('firstname'),
'lastName' => $this->input->post('lastname'),
'address' => $this->input->post('address'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
'username' => $this->input->post('username'),
'password'=> $this->input->post('password')
);
$this->register_model->insertUsers($data);
}
}
注册模型文件:
<?php
class register_model extends CI_Controller {
//Insert a new user to users table when registration form submits
function insertUser(){
$query = $this->db->query();
}
}
?>
任何帮助表示赞赏:)
【问题讨论】:
-
这是整个
register_model文件吗? -
@DFriend 是的,这就是整个文件,我要做的就是将表单中的数据插入数据库。稍后我会将查询插入到查询函数中。
-
错误信息究竟是什么时候出现的?当你加载页面?什么时候提交表格?
-
@DFriend 当表单通过所有验证并提交时
-
如果从
validateRegForm中删除(或注释掉)$this->register_model->insertUsers($data);会发生什么?仍然得到错误?
标签: php codeigniter model-view-controller