首页 > 解决方案 > CodeIgniter - 消息:未定义的属性:Account_login::$login & 调用非对象上的成员函数模型()

问题描述

想就这些错误寻求帮助。

控制器名称:Account_login.php 模型名称:account_login_model.php

消息:未定义属性:Account_login::$login 文件名:controllers/account_login.php 行号:34 回溯:文件:C:\xampp\htdocs\labexercise009\application\controllers\account_login.php 行:34 函数:_error_handler 文件:C :\xampp\htdocs\labexercise009\application\controllers\account_login.php 行:21 功能:运行 文件:C:\xampp\htdocs\labexercise009\index.php 行:315 功能:require_once

在非对象上 调用成员函数 model() 消息:在 null 上调用成员函数 model() 文件名:C:\xampp\htdocs\labexercise009\application\controllers\account_login.php 行号:34 回溯:文件: C:\xampp\htdocs\labexercise009\application\controllers\account_login.php 行:21 功能:运行 文件:C:\xampp\htdocs\labexercise009\index.php 行:315 功能:require_once

这是我的代码:

控制器

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

模型

    <?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('lslayugan@feutech.edu.ph', '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;
  }
}

标签: phpcodeigniter

解决方案


可能会像这样改变 $this->load->model('account_login_model');

而不是 $this->login->model('account_login_model');


推荐阅读