I hope somebody will explain or help me to find out what the problem is. I have such an error while trying to register.
Message: Undefined property: Pages::$user_model. Call to a member function email_check() on null.
Also, It says that I should check line 45. Here is this line and line above:
$this->load->model('User_model');
$email_check=$this->user_model->email_check($user['email']);
So, this is my controller. I use database "mysite", table "mysite".
class Pages extends CI_Controller {
function view($page ='home'){
$this->load->helper('url');
$this->load->model('User_model');
$this->load->library('session');
$data['title'] = $page;
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page);
$this->load->view('templates/Navigation', $data);
$this->load->view('templates/footer', $data);
}
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('User_model');
$this->load->library('session');
}
public function index()
{
$this->load->helper('url');
$this->load->model('User_model');
$this->load->library('session');
$this->load->view("Register.php");
}
public function register_user(){
$this->load->helper('url');
$this->load->model('User_model');
$this->load->library('session');
$user=array(
'username'=>$this->input->post('username'),
'email'=>$this->input->post('email'),
'password'=>md5($this->input->post('password')),
'age'=>$this->input->post('age'),
'phone'=>$this->input->post('phone')
);
print_r($user);
$this->load->model('User_model');
$email_check=$this->user_model->email_check($user['email']);
if($email_check){
$this->load->model('User_model');
$this->user_model->register_user($user);
$this->session->set_flashdata('success_msg', 'Registered successfully.Now login to your account.');
redirect('pages/login_view');
}
else{
$this->load->model('User_model');
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
redirect('pages');
}
}
public function login_view(){
$this->load->view("pages/Login");
}
function login_user(){
$this->load->model('User_model');
$user_login=array(
'email'=>$this->input->post('email'),
'password'=>md5($this->input->post('password')));
$this->load->model('User_model');
$data=$this->User_model->login_user($user_login['email'],$user_login['password']);
if($data)
{
$this->session->set_userdata('user_id',$data['user_id']);
$this->session->set_userdata('email',$data['email']);
$this->session->set_userdata('username',$data['username']);
$this->session->set_userdata('age',$data['age']);
$this->session->set_userdata('phone',$data['phone']);
$this->load->view('pages/User_profile');
}
else{
$this->load->model('User_model');
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view("pages/Login");
}
}
function user_profile(){
$this->load->model('User_model');
$this->load->view('user_profile.php');
}
public function user_logout(){
$this->load->model('User_model');
$this->session->sess_destroy();
redirect('pages/login_view', 'refresh');
}
}
?>
And this is my User_model. Actually, i have no idea where problem is.
<?php
class User_model extends CI_model{
public function register_user($user){
$this->db->insert('mysite', $user);
}
public function login_user($email,$password){
$this->db->select('*');
$this->db->from('mysite');
$this->db->where('email',$email);
$this->db->where('password',$password);
if($query=$this->db->get())
{
return $query->row_array();
}
else{
return false;
}
}
public function email_check($email){
$this->db->select('*');
$this->db->from('mysite');
$this->db->where('email',$email);
$query=$this->db->get();
if($query->num_rows()>0){
return false;
}else{
return true;
}
}
}
?>