Welcome Guest, Not a member yet? Register   Sign In
Call to a member function login_model()
#1

(This post was last modified: 04-15-2020, 01:19 PM by jreklund.)

I'm new in CI. Can someone help me with this error?

//START OF ERROR
Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: Main::$crud_model

Filename: controllers/main.php

Line Number: 297

Backtrace:

File: D:\Apache24\htdocs\framework\application\controllers\main.php
Line: 297
Function: _error_handler

File: D:\Apache24\htdocs\framework\index.php
Line: 315
Function: require_once

Fatal error: Call to a member function login_model() on a non-object in D:\Apache24\htdocs\framework\application\controllers\main.php on line 297
A PHP Error was encountered
Severity: Error

Message: Call to a member function login_model() on a non-object

Filename: controllers/main.php

Line Number: 297

Backtrace:

//CODE
PHP Code:
public function check_login(){

        
$this->load->library('form_validation');

        
$this->form_validation->set_rules('email''Email''required');

        
$this->form_validation->set_rules('password''Password''required');

        if(
$this->form_validation->run()){

            
$email $this->input->post('email');

            
$password $this->input->post('password');

            
$num_row $this->crud_model->login_model($email$password);

            
//Validate Login / 0 = not valid / 1 = valid
                
if($num_row->num_rows() > ){

            
//Statement of valid login
            //nag foreach ako then kinuha ko ay $user_id then nilagay ko sa variable na $my_id
                
foreach($num_row->result() as $row):
                    
$my_id['user_id'] = $row->user_id;
                endforeach;
            
                
//Means: $_SESSION['user_id'] = $my_id
                    
$this->session->set_userdata($my_id);

                
//Means: $user_id = $_SESSION["user_id"];
                    
$user_id $this->session->userdata('user_id');
                
                
//Function check_session in main.php
                    
redirect(base_url() . 'main/check_session');

                }else{
                    
redirect(base_url() . 'main/login' '?email=' md5(rand(1,1000)));
                
                }
                
                }else{
                    
$this->login();
            }
         } 

//CODE for crud_model->login_model
PHP Code:
function login_model($email$password){

        
$this->db->where('email'$email);

        
$this->db->where('password'$password);

        
$query $this->db->get('tusers');

        return 
$query;
    } 
Reply
#2

@soljon,

I'm assuming that you are using CI3. Assuming that this is the case did you load the model crud_model into the class where the check_login function is located? Can we see the beginning of the class code where the check_login function is located?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB