2014-12-27 58 views
-2

我有這個PHP代碼,它做了測試並運行它,如果測試結果爲真。但即使它得到錯誤的結果,CastResult也會忽略if檢查。爲什麼我的PHP如果週期不能正常工作

private function canVote($user,$id) 
{ 
     $userVoted = VoteModel::where('user',$user)->where('post',$id)->get(); 
     if(count($userVoted)==0) 
      { 
       $canVote=true; 
      } 
     else { 
      $canVote=false; 
     } 
     return $canVote; 
    } 
    private function castVote($mode) 
    { 
     $user = Auth::getUser(); 
     $id = $this->param('id'); 

     if($this->canVote($user,$id)) 
     { 
      $newVote = new VoteModel; 
      $newVote->user = $user['name']; 
      //other stuff 

     } else 
      { 
       Flash::error('Err'); 
      } 
    } 
+0

是什麼'?CastVesult' – 2014-12-27 18:51:54

+0

對不起,錯了,修正了它 – Hunrik 2014-12-27 19:07:31

+0

好吧,現在它是'CastResult'這也是不可見的......? – 2014-12-28 07:37:41

回答

0

更加簡單明瞭,沒有未定義的變量:

private function canVote($user,$id) 
{ 
    $userVoted = VoteModel::where('user',$user)->where('post',$id)->get(); 
    return (count($userVoted) === 0); 
} 
+0

謝謝,但它不能解決問題 – Hunrik 2014-12-27 19:06:06