/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Modelo::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, 'id_marca' => $this->id_marca]);
     $query->andFilterWhere(['like', 'nome', $this->nome]);
     return $dataProvider;
 }
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ModeloSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Modelos';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="modelo-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Novo Modelo', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'nome', ['attribute' => 'id_marca', 'filter' => Html::activeDropDownList($searchModel, 'id_marca', ArrayHelper::map(Modelo::find()->asArray()->all(), 'id', 'nome'), ['class' => 'form-control', 'prompt' => 'Filtrar'])], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
 public function afterFind()
 {
     $this->id_cor = Cor::findOne($this->id_cor)->nome;
     $this->id_tipo_combustivel = TipoCombustivel::findOne($this->id_tipo_combustivel)->nome;
     $this->id_modelo = Modelo::findOne($this->id_modelo)->nome;
     switch ($this->status) {
         case '1':
             $this->status = 'Leiloado';
             break;
         case '2':
             $this->status = 'Disponível';
             break;
         case '3':
             $this->status = 'Alocado';
             break;
     }
 }
 /**
  * Finds the Modelo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Modelo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Modelo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getModelos()
 {
     return $this->hasMany(Modelo::className(), ['id_marca' => 'id']);
 }
?>

    <?php 
echo $form->field($model, 'placa_atual')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'placa_anterior')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'potencia')->textInput();
?>

    <?php 
echo $form->field($model, 'id_modelo')->dropDownList(ArrayHelper::map(Modelo::find()->all(), 'id', 'nome'), ['prompt' => 'Selecione uma opção']);
?>

    <?php 
echo $form->field($model, 'id_cor')->dropDownList(ArrayHelper::map(Cor::find()->all(), 'id', 'nome'), ['prompt' => 'Selecione uma opção']);
?>

    <?php 
echo $form->field($model, 'id_tipo_combustivel')->dropDownList(ArrayHelper::map(TipoCombustivel::find()->all(), 'id', 'nome'), ['prompt' => 'Selecione uma opção']);
?>

    <?php 
echo $form->field($model, 'ano_fabricacao')->dropDownList(array_combine(range(date('Y') + 1, 1900, -1), range(date('Y') + 1, 1900, -1)), ['prompt' => 'Selecione uma opção']);
?>

    <?php