/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CouponType::find(); $query->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); if ($this->load($params) && !$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'money' => $this->money, 'min_amount' => $this->min_amount, 'type' => $this->type, 'started_at' => $this->started_at, 'ended_at' => $this->ended_at, 'min_goods_amount' => $this->min_goods_amount, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/* @var $searchModel common\models\CouponSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Coupons'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="coupon-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <!--p> <?php echo Html::a(Yii::t('app', 'Create ') . Yii::t('app', 'Coupon'), ['create'], ['class' => 'btn btn-success']); ?> </p--> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'user_id', 'value' => function ($model) { return $model->user ? $model->user->username : '******'; }], ['attribute' => 'coupon_type_id', 'format' => 'html', 'value' => function ($model) { return $model->couponType ? $model->couponType->name : '-'; }, 'filter' => Html::activeDropDownList($searchModel, 'coupon_type_id', ArrayHelper::map(\common\models\CouponType::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => Yii::t('app', 'Please Filter')])], 'money', 'min_amount', 'started_at:date', 'ended_at:date', 'sn', ['attribute' => 'order_id', 'value' => function ($model) { return $model->order_id ? $model->order_id : '-'; }], ['attribute' => 'used_at', 'value' => function ($model) { return $model->used_at ? Yii::$app->formatter->asDatetime($model->used_at) : '-'; }], 'created_at:date', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}']]]); ?> </div>