/** * 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>
?> <?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