2016-04-07 50 views
0

Ben sınıfları ile giriş oluşturduk ama bana bir hata verir UserController tanımsız yöntemine çağrıÖlümcül hata: Yakalanmayan Hata:

(!) Fatal error: Uncaught Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\User Controller.php on line 17

(!) Error: Call to undefined method UserController::checkLogin() in C:\xampp\htdocs\progettoPersonale\controllers\User Controller.php on line 17 Call Stack # Time Memory Function Location 1 0.0010 360312 {main}() ...\login.php:0 2 0.0030 384208 UserController->__construct() ...\login.php:7

iki sınıfları şunlardır: hat 17 üzerinde

class UserController 
{ 
    public $username = ''; 
    private $logged = false; 
    private $usermodel = ''; 

    public function __construct() 
    { $this->usermodel = new UserModel(); 
     session_start(); 


     if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_GET['action'])&& $_GET['action']== 'login'){ 
      $username = (isset($_POST['username']))? $_POST['username'] :false ; 
      $password = (isset($_POST['password']))? $_POST['password'] :false ; 
      var_dump($password,$username); 
      if ($username !=false && $password !=false && $this->usermodel->checkLogin($username, $password)){ 

       $this->username =$username ; 
       $this->logged = true ; 

       $_SESSION['username']= $username ; 
       $_SESSION['logged']= true ; 
       $_SESSION[ 'message' ] = 'Login effettuato correttamente'; 
      }else{ 
       $_SESSION[ 'message' ] = 'Errore con il login; riprovare!'; 
      } 
     } 
     elseif (isset($_GET['action'])&& $_GET['action']== 'logout'){ 
      unset($_SESSION['username']); 
      unset($_SESSION['logged']); 
      $_SESSION[ 'message' ] = 'Logout effettuato correttamente'; 
     } 
     elseif (isset($_SESSION['username'])&& isset($_SESSION['logged'])){ 

      $this->username = $_SESSION['username'] ; 
      $this->logged = true ; 
     } 
     $this->redirectToProperArea(); 
    } 
class UserModel 
{ 
    private $dbconn = null ; 

    public function __construct() 
    { 
     $this->dbconn = new DbConnector(); 
    } 


    public function checkLogin($username, $password){ 

     $newpassword =password_hash($password, PASSWORD_DEFAULT); 

     $res=$this->dbconn->select(
      array('id_utente'), 
      'iscritti', 
      'nome_utente='.$username.'&& password='.$newpassword 

     ); 
     $num_rows=$this->dbconn->num_rows($res); 
     if ($num_rows ==1){ 
      return true ; 
     }else { 
      return false ; 
     } 
    } 
} 
+0

'u çağırmanız gerekir. Bu, tek bir dosyadan tam bir kopyala yapıştır mı? Çünkü, 'UserController' sınıfını kapatmak için' '' eksik. –

cevap

1

, sen UserController::checkLogin() çağırıyor, ancak Kullanıcı Denetleyici sınıfında checkLogin yöntemi yok. Bu işlev UserModel sınıfına aittir, bu nedenle bunun yerine UserModel::checkLogin()

+0

Çağrı '$ this-> usermodel-> checkLogin (..' ve önceden tanımlanan özellik '$ this-> usermodel = new UserModel();' bu işi iyi yapmalı – rjdown

İlgili konular