/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'pid' => $this->pid, 'level' => $this->level, 'cover' => $this->cover, 'created_at' => $this->created_at, 'status' => $this->status]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_description', $this->seo_description]); return $dataProvider; }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="category-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'class' => 'form-horizontal']]); $form->fieldConfig = ['template' => '{label}<div class="col-sm-5">{input}{hint}{error}</div>', 'labelOptions' => ['class' => 'control-label col-sm-1']]; ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'pid')->dropDownList(Category::selTree(), ['prompt' => '顶级']); ?> <?php echo $form->field($model, 'cover')->fileInput(); ?> <?php echo $form->field($model, 'body')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'seo_title')->textInput(['maxlength' => true]); ?> <?php