Wednesday, February 21, 2018

php - CodeIgniter Auto Loading form_validation causes Error with Model files

I am using CodeIgniters form_validation library to validate a form in my app. Library loaded here:



$autoload['libraries'] = array('database','form_validation');


Ever since including the library I cannot load any models in the app. I get the following error in my browser. The form is a registration form for users to sign up to the site. The form gets validated perfectly.



 A PHP Error was encountered

Severity: Notice


Message: Undefined property: register_model::$load

Filename: libraries/Form_validation.php

Line Number: 147


Here is my function that tries to load the model:




  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);
}
}


Register model file:




  class register_model extends CI_Controller {

//Insert a new user to users table when registration form submits
function insertUser(){

$query = $this->db->query();

}


}

?>


Any help is appreciated :)

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...