php - Variable not returning a boolean yii 2 -


i have been working on code return boolean value, happens variable gets overwritten true or false looks row in foreach statements. when pass in view file no value taken/appears. can me why happening , how pass boolean?

view file

echo testcontroller::showprerequisites(29005); 

model

$validator;  foreach($prereq $values){   if(finishedsubjects::find()->where(['subjectname' => $values['col']])->exists()){    $validator = true;  } else {    $validator = false;  }  }  return $validator; 

controller

  public function showprerequisites($trno){       $model = new testmodel();       return $model->showprerequisites($trno);     } 

edit view update

$preq =  testcontroller::showprerequisites(29005);  if($preq = true){     echo 'pre requites completed/read'; } else if($preq = false) {     echo 'pre requisites not completed/not read'; } 

you have logical error in code, assigning value in if condition , checking, return true.

instead of this:

if($preq = true){ 

you can check way too:

if($preq){ // if $preq true line work. 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -