Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义的属性:登录\控制器::$user_Php_Codeigniter - Fatal编程技术网

Php 未定义的属性:登录\控制器::$user

Php 未定义的属性:登录\控制器::$user,php,codeigniter,Php,Codeigniter,为什么会出现这个错误?我已经在图书馆里加载了数据库, 但这是一个错误 未定义的属性:登录\控制器::$user 我一直在做登录验证 这是我的自动装弹机 $autoload['model'] = array(); $autoload['helper'] = array('url'); $autoload['libraries'] = array('database', 'session','form_validation'); 这是我的登录控制器 <?php defined('

为什么会出现这个错误?我已经在图书馆里加载了数据库, 但这是一个错误

未定义的属性:登录\控制器::$user

我一直在做登录验证

这是我的自动装弹机

$autoload['model'] = array();

$autoload['helper'] = array('url');

$autoload['libraries'] = array('database', 'session','form_validation');   
这是我的登录控制器

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_Controller extends CI_Controller
{
    public function __construct() {        
        parent::__construct();
    }

     public function index()
    {
        $this->load->view('login');
    }
    function verify()
    {
        $this->load->model('user_model');
        $check = $this->user->validate();
        //$this->load->library('database');
        if($check)
        {
            $this->load->view('admin/main');
        }
        else
        {
            $this->load->view('login');
            $message = "Username and/or Password incorrect.\\nTry again.";
            echo "<script type='text/javascript'>alert('$message');</script>";
        }

    }
}

感谢您的帮助

更新
$this->load->model('user_model')
$this->load->model('user_model','user')

并更新行
$this->db->get_where('user',$array)->result()
to
return$this->db->get_where('user',$array)->result()在用户模型中
验证
方法

  • 换行
  • 更新
    validate()
    函数,如下所示

  • 加载用户模型时
    $this->load->model('user_model')默认情况下,它将用户模型类对象分配给
    Login\u Controller
    中的
    User\u model
    变量。您可以通过
    $this->user\u model
    访问它

    因此,当您使用
    $this->User->validate()访问
    User\u model
    类方法
    validate
    您收到错误
    未定义属性:Login\u Controller::$user

    如果要使用
    user
    variable pass第二个参数到加载模式方法,如下所示:
    $this->load->model('user_model','user')

    请不要使用代码和错误消息的屏幕截图,因此请编辑完整的错误消息。我在您的代码示例中没有看到任何
    $user
    ?请使用Line17更新对不起,第17行是
    $check=$this->user->validate()这样来自模型的调用我已经修复了它,但无法登录$this->User_model->validate();并确保该模型是User_model.php,需要大写第一个字母
    
    class User_model extends CI_Model 
    {
        public function __construct() {        
            parent::__construct();
        }
        function validate()
        {
            $array['username'] = $this->input->post('username');
            $array['password'] = $this->input->post('password');
            $this->db->get_where('user',$array)->result();
        }
    
    }
    
    $check = $this->user->validate();
    
    $check = $this->user_model->validate();
    
    function validate(){
         $array['username'] = $this->input->post('username');
         $array['password'] = $this->input->post('password');
         return $this->db->get_where('user',$array)->num_rows();
    }