/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Motorista::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(['cnh' => $this->cnh, 'telefone' => $this->telefone]);
     $query->andFilterWhere(['like', 'nome', $this->nome])->andFilterWhere(['like', 'categoria_cnh', $this->categoria_cnh])->andFilterWhere(['like', 'tipo', $this->tipo])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdMotorista()
 {
     return $this->hasOne(Motorista::className(), ['cnh' => 'id_motorista']);
 }
?>

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

    <?php 
echo $form->field($model, 'id_veiculo')->dropDownList(ArrayHelper::map(Veiculo::find()->all(), 'renavam', 'placa_atual'), ['prompt' => 'Selecione uma opção']);
?>

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

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

    <?php 
echo $form->field($model, 'data_abastecimento')->widget(DatePicker::className(), ['inline' => false, 'language' => 'pt', 'clientOptions' => ['autoclose' => true, 'format' => 'dd-mm-yyyy']]);
?>
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Novo' : 'Atualizar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>
use yii\grid\GridView;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $searchModel app\models\MotoristaSearch */
/* @var $model app\models\Motorista */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Motoristas';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="motorista-index">

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

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

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'nome', 'cnh', 'categoria_cnh', ['attribute' => 'tipo', 'filter' => Html::activeDropDownList($searchModel, 'tipo', Motorista::getTipo(), ['class' => 'form-control', 'prompt' => 'Filtrar'])], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
 /**
  * Finds the Motorista model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Motorista the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Motorista::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }