2014-12-27 4 views
-2

이 PHP 코드는 테스트를 수행하고 테스트 결과가 true이면 실행합니다. 그러나 잘못된 결과를 얻더라도 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' 무엇인가? –

+0

죄송합니다. 잘못 입력 했으므로 수정했습니다. – Hunrik

+0

이제 CastResult도 보이지 않습니다 ...? –

답변

0

더 간단하고 명확하고 더 정의되지 않은 변수가 없습니다 :

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

고마워요.하지만 문제가 해결되지 않았어요. – Hunrik

관련 문제