2013-10-31 92 views
0

當用戶名或密碼錯誤時,出現此錯誤。正確的用戶名和密碼時運行成功。 調用一個成員函數count()在....調用非對象的成員函數count()

我的代碼非對象是

public function executeLogin(sfWebRequest $request) 
{ 
    $this->form = new loginForm(); 

    if ($request->isMethod('post')) 
    { 
     $this->form->bind($request->getParameter('login')); 
     if ($this->form->isValid()) 
     { 
      $unm=$this->form->getValue('username'); 
      $pwd=$this->form->getValue('password'); 
      $q = Doctrine_Query::create() 
      ->select('id') 
      ->from('login') 
      ->andWhere('username = ?', $unm) 
      ->andWhere('password = ?', $pwd); 
      $q->execute(); 
      $result = $q->fetchOne(); 
      if ($result->count() > 0) 
      {    
       $this->getUser()->setAuthenticated(true); 
       $this->getUser()->addCredential('user'); 
       $this->redirect('user/index'); 
      } 
      else 
      { 
       $this->redirect('user/login'); 
      } 
     } 
    } 
} 
+0

請,張貼棧回溯。 – Jacobson

+0

我是新的symfony1.4,所以我不知道你想要什麼 – hemsbhardiya

回答

2

$結果值有NULL值。你應該先檢查一下。讓我們改變的條件如下:

if ($result && $result->count() > 0) {...} 

甚至

if ($result) {...} 
+0

謝謝romik。工作很好。 – hemsbhardiya

相關問題