0

Possible Duplicate:
Reference - What does this error mean in PHP?

I saw many questions about my problem, but, unfortunately, without fix.

So, my syntax's error is:

Fatal error: Using $this when not in object context in ... on line 18.

My line 18:

      echo $this->login;

My full code:

<?php

class LoginModel extends LoginController {

    private $_db;
    public $login;
    public $pass;

    public function __construct() {

        $this->_db = Db::getInstance();
        $this->login = addslashes(trim($_GET['tgo-root-user']));
        $this->pass = addslashes(trim(md5($_GET['tgo-root-password'].SALT)));

    }

    public function auth() {
        echo $this->login;
        /*$pdo = $this->_db->prepare( "SELECT * FROM `tgo_users` WHERE ((:login = `user_login`) OR (:login = `user_email`)) AND (:user_pw = `user_pw`) " );
        $pdo->bindParam( ":login", $this->login, PDO::PARAM_STR );
        $pdo->bindParam( ":user_pw", $this->pass, PDO::PARAM_STR );
        $pdo->execute();

        if( $pdo->rowCount() == 1 ) {
            return true;
        } else {
            return false;
        }*/

    }


}

My call:

<?php

class LoginController {

    public static $status;

    public function authenticate() {

        $model = new LoginModel();
        $this->status = $model->auth();

        LoginView::emitAuthResponse();

    }


}

So I ask: what's wrong? Damn.. I'm loosing to much time with this problem and I don't know what's wrong.

Thank you.

Community
  • 1
  • 1
Guilherme Oderdenge
  • 4,935
  • 6
  • 61
  • 96

3 Answers3

2

You propably call it like

LoginModel::auth();

auth() is not static, thus you need an object of LoginModel to call it.

$x = new LoginModel;
$x->auth();
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
1

If you want to use "$this", then you can't have $status be static. I think it is screwing up here...

$this->status = $model->auth();
theDazzler
  • 1,039
  • 2
  • 11
  • 27
1

Use debug_print_backtrace() to look at the call stack and figure out where you're calling LoginModel::auth() statically.

FtDRbwLXw6
  • 27,774
  • 13
  • 70
  • 107