/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Turma::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'descricao', $this->descricao]);
     return $dataProvider;
 }
 /**
  * Finds the Turma model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Turma the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Turma::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
use yii\helpers\ArrayHelper;
use app\models\Turma;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Avaliacao */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="avaliacao-form">

    <?php 
$form = ActiveForm::begin(['method' => 'GET', 'action' => \yii\helpers\Url::to(['avaliacao/avaliar'])]);
?>

    <?php 
echo $form->field($turma, 'id')->dropDownList(ArrayHelper::map(Turma::find()->all(), 'id', 'descricao'), ['prompt' => '---- Turmas ----', 'name' => 'turma'])->label('Selecione a sua turma');
?>



    <div class="form-group">
        <?php 
echo Html::submitButton('Avaliar', ['class' => 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
 public function actionAvaliar($turma = null)
 {
     if (empty($turma)) {
         $turma = new Turma();
         return $this->render('turma', ['turma' => $turma]);
     } else {
         $avaliacao = new Avaliacao();
         $turma = Turma::findOne(['id' => $turma]);
         $itens = Item::find()->all();
         if (Yii::$app->request->post()) {
             $avaliacao = Yii::$app->request->post('Avaliacao');
             $ok = true;
             foreach ($avaliacao as $a) {
                 $av = new Avaliacao();
                 $av->id_item = $a['id_item'];
                 $av->id_turma = $a['id_turma'];
                 $av->id_avaliado = $a['id_avaliado'];
                 $av->importancia = $a['importancia'];
                 $av->satisfacao = $a['satisfacao'];
                 $av->descricao = $a['descricao'];
                 if (!$av->save()) {
                     return new HttpException(500, 'Houve um erro ao salvar a sua avaliação :\'(');
                 }
             }
             return $this->render('obrigado');
         } elseif ($turma) {
             return $this->render('avaliar', ['itens' => $itens, 'turma' => $turma]);
         } else {
             throw new HttpException(404, 'Turma Inválida :/');
         }
     }
 }