尝试获取CI中非对象的属性

时间:2018-08-18 10:31:08

标签: database codeigniter-3

遇到PHP错误 严重程度:通知

消息:试图获取非对象的属性

文件名:controllers / Auth.php

行号:35

回溯:

文件:C:\ xampp \ htdocs \ Codeigniter \ application \ controllers \ Auth.php 行:35 功能:_error_handler

文件:C:\ xampp \ htdocs \ Codeigniter \ index.php 线:315 功能:require_once

我的代码:

enter image description here

public function login()
    {
        $this -> form_validation ->set_rules('username', 'Username', 'required');
        $this -> form_validation ->set_rules('password', 'Password', 'required|min_length[5]');

        if ($this->form_validation->run() == TRUE) {
            # code...

            $username = $_POST['username'];
            $password = $_POST['password'];

            $this->db->select('*');
            $this->db->from('login');
            $this->db->where(array('username' => $username, 'password' => $password));
            $query = $this ->db->get();

            $user = $query->row();

            if ($user->email) {

                $this->session->set_flashdata("success", "You are Successfull Logged in");

                $_SESSION['user_logged'] = TRUE;
                $_SESSION['username'] = $user->username;

                redirect("user/profile", "refresh");
            }else{

                $this->session->set_flashdata("error", "Invalid Login details");
                //redirect("auth/login", "refresh");
            }
        }
    # code...
    $this -> load ->view('login');
}

0 个答案:

没有答案