• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter - Message: Undefined property: Account_login::$login & Call to a member f

#1
Wanted to seek a help on these errors.
controller name: Account_login.php model name: account_login_model.php
[b]Message: Undefined property: Account_login::$login[/b] Filename: controllers/account_login.php Line Number: 34 Backtrace: File: C:\xampp\htdocs\labexercise009\application\controllers\account_login.php Line: 34 Function: _error_handler File: C:\xampp\htdocs\labexercise009\application\controllers\account_login.php Line: 21 Function: run File: C:\xampp\htdocs\labexercise009\index.php Line: 315 Function: require_once
[b]Call to a member function model() on a non-object[/b] Message: Call to a member function model() on null Filename: C:\xampp\htdocs\labexercise009\application\controllers\account_login.php Line Number: 34 Backtrace: File: C:\xampp\htdocs\labexercise009\application\controllers\account_login.php Line: 21 Function: run File: C:\xampp\htdocs\labexercise009\index.php Line: 315 Function: require_once
Here's my code:
[b]Controller[/b]


Code:
?php

class Account_login extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $data['title'] = 'Account Login';
    $this->load->view('account_login', $data);
  }

  public function verify()
  {
    $this->form_validation->set_rules('txtuser', 'Username', 'required');
    $this->form_validation->set_rules('txtpass', 'Password', 'required|callback_check_user');

    if ($this->form_validation->run() == TRUE) {
      echo 'Success';
    } else {
      $this->index();
    }
  }

  public function check_user()
  {
    $username = $this->input->post('txtuser');
    $password = $this->input->post('txtpass');


    $this->login->model('account_login_model');
    $login = $this->account_login_model->login($username, $password);


    if ($login) {
      return true;
    } else {
      if (isset($_SESSION['error_count'][$username])) {
        $_SESSION['error_count'][$username] += 1;
      } else {
        $_SESSION['error_count'][$username] = 1;
      }

      $isBlocked = $this->account_login_model->isBlocked($username);
      if ($isBlocked) {
        $this->form_validation->set_message('check_user', 'Account is temporarily blocked.');
      } else if (isset($_SESSION['error_count'][$username]) && $_SESSION['error_count'][$username] > 2) {
        $this->account_login_model->block($username);
        $this->form_validation->set_message('check_user', '3 consecutive failed login attempts. Account Blocked.');
      } else {
        $this->form_validation->set_message('check_user', 'Invalid Username/Password');
      }
      return false;
    }
  }
}
[b][b]Model[/b][/b]

Code:
<?php
class Account_login_model extends CI_Model
{
  public function __construct()
  {
    parent::__construct();
    $this->load->database();
  }

  public function login($username, $password)
  {
    $condition_array = array(
      'user_name' => $username,
      'user_pass' => $password
    );
    $rs = $this->db->get_where('users', $condition_array);

    $row_count = count($rs->row_array());

    if ($row_count > 0) {
      return $rs->row_array();
    } else {
      return FALSE;
    }
  }

  public function isBlocked($username)
  {
    $condition_array = array(
      'user_name' => $username,
      'acc_isBlocked' => 1
    );
    $rs = $this->db->get_where('accounts', $condition_array);
    $row_count = count($condition_array);

    if ($row_count > 0) {
      return true;
    } else {
      return FALSE;
    }
  }

  public function block($username)
  {
    $this->load->library('email');

    $email = $this->account_lookup($username, 'acc_email');

    $this->email->from('[email protected]', 'Your Website');
    $this->email->to($email);
    $this->email->subject('Account Blocked');

    $message = $this->load->view('account_blocked', null, TRUE);

    $this->email->message($message);
    $this->email->send();

    $this->db->where('acc_username', $username);
    return $this->db->update('accounts', array('acc_isBlocked' => 1));
  }

  public function account_lookup($username, $return)
  {
    $rs = $this->db->get_where('account', array('acc_username' => $username));
    $row = $rs->row();
    return $row->$return;
  }
}
Reply

#2
use $this->load->model() instead
Reply

#3
(09-23-2020, 03:02 AM)paulbalandan Wrote: use $this->load->model() instead

The heck, how did I missed that. Thanks alot Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.