简体   繁体   English

致命错误:在非对象中调用成员函数login()

[英]Fatal error: Call to a member function login() on a non-object in

Got an issue with a web app that I've inherited as a project and unfortunately I can't trace the error. 遇到了我作为项目继承的Web应用程序的问题,很遗憾,我无法跟踪该错误。 It seems that the model isn't being loaded but I could be wrong. 似乎未加载模型,但我可能是错的。 Any help would be great. 任何帮助都会很棒。

code is: 代码是:

public function login()
{

    //If request is post then user is trying to login, so process the login info
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {

        //Run the model method ::login
        $login_successful = $this->User->login();

        // check login status
        if($login_successful) {
            // if YES, then move user to dashboard/index (btw this is a browser-redirection, not a rendered view!)
            header('location: ' . URL . 'passwords/index');
        } else {
            echo "Incorrect user / pass combination entered. Please try again.";
        }


    }

}

and the model function is: 并且模型函数是:

public function login() {

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


    $bind = array(
        ":username" => "$username",
    );
    $result = $this->select("users", "username = :username", $bind);

    //Check the password returned from the db against the password entered
    if (Bcrypt::checkPassword($password, $result[0]['password']) == true) {
        Session::init();

        Session::set('user_logged_in', true);
        Session::set('user_id', $result[0]['id']);
        Session::set('user_name', $result[0]['username']);
        Session::set('user_permission', $result[0]['permission']);
        Session::set('user_role', $result[0]['role']);

        return true;
    } else {
        return false;
    }
}

also I've noticed that the controller and model both have a function called login.] 我也注意到控制器和模型都有一个名为login的函数。]

Thanks 谢谢

The reason is $this->User is not a valid class instance. 原因是$this->User不是有效的类实例。

Make sure that it is an object. 确保它是一个对象。

Try 尝试

var_dump($this->User);
die();
//Run the model method ::login
$login_successful = $this->User->login();

And you will see that there is no instance there. 您将看到那里没有实例。

What to do? 该怎么办?

Find the place where you expect your model being initialized. 找到您希望模型初始化的位置。 Check, why it is not. 检查,为什么不是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误在非对象PHP上调用成员函数login() - Fatal Error Call to a member function login() on a non-object PHP 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error 致命错误:在cakephp登录应用程序中的非对象上调用成员函数create() - Fatal error: Call to a member function create() on a non-object in cakephp login application 致命错误:在非对象上调用成员函数check_login() - Fatal error: Call to a member function check_login() on a non-object Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object CakePHP致命错误调用非对象上的成员函数schema() - CakePHP Fatal Error Call to a member function schema() on a non-object 致命错误:在非对象上调用成员函数 getElementsByTagName() - Fatal error: Call to a member function getElementsByTagName() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM