php - 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;
}
}
解决方案
可能会像这样改变 $this->load->model('account_login_model');
而不是 $this->login->model('account_login_model');
推荐阅读
- python - 了解 return [0,size-1][nums[0]
在处理一个简单的编码问题,编写一个函数
findPeakElement
时,我遇到了以下代码:def findPeakElement(self, nums): size = len(nums) for x in range(1,size-1):
- c - 我应该如何使用命令行参数从文件中填充整数数组?文件的大小和编号。的元素可能会有所不同
- android - Android-studio 3.4.0-3.4.2 Gradle 错误:没有为属性“manifestOutputDirectory”指定值
- mysql - 如何在sql中使用当前时间获取时间范围
- java - 使用 Postgresql 休眠未正确加载具有“文本”数据类型的列的数据
- spring-boot - 如何使用我自己的 findById 声明而不是 Spring Data 的声明?
- node.js - 如何将 Socket.io React 应用程序部署到 Heroku
- javascript - 如何修复芯片数据不显示
- sql - 如何创建查询以在 Oracle 的一行中以逗号分隔格式获取多行数据
- javascript - 如何检测发送到我的 REST http post 端点的空 JSON 数据?它破坏了我的服务器代码