/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Lunbo::find()->orderBy('status desc,id desc'); $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, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'order', $this->order]); return $dataProvider; }
/** * Finds the Lunbo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Lunbo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Lunbo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'info')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'content')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'event_link')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'share_link')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'type')->dropDownList(\common\models\cms\Lunbo::type_labels()); ?> <?php echo $form->field($model, 'status')->dropDownList(\common\models\cms\Lunbo::status_labels()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
<p> <?php echo Html::a('创建轮播图', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', 'url:url', 'order', 'info', 'event_link', 'share_link', ['attribute' => 'type', 'format' => 'html', 'value' => function ($model) { if ($model->type == \common\models\cms\Lunbo::TYPE_LUNBO) { $class = 'label-success'; } elseif ($model->status == \common\models\cms\Lunbo::TYPE_QIDONG) { $class = 'label-warning'; } else { $class = 'label-danger'; } return '<span class="label ' . $class . '">' . $model->typeLabel . '</span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'status', \common\models\cms\Lunbo::getArrayType(), ['class' => 'form-control', 'prompt' => '请筛选'])], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { if ($model->status == \common\models\cms\Lunbo::STATUS_SUCCESS) { $class = 'label-success'; } elseif ($model->status == \common\models\cms\Lunbo::STATUS_DELETED) { $class = 'label-warning'; } else { $class = 'label-danger'; } return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'status', \common\models\cms\Lunbo::getArrayStatus(), ['class' => 'form-control', 'prompt' => '请筛选'])], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * 获取启动页 * @return array */ public static function cms_qidong() { $lunbo = Lunbo::find()->select(['title', 'url', 'order', 'info', 'content', 'event_link'])->where(['status' => Lunbo::STATUS_SUCCESS, 'type' => Lunbo::TYPE_QIDONG])->orderBy('order desc,id desc')->asArray()->all(); if (!empty($lunbo)) { $data = array('list' => $lunbo); $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => $data); return $result; } else { $result = array('errorNum' => '1', 'errorMsg' => '暂无图片', 'data' => null); return $result; } }