/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CourseTerms::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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'parent_id' => $this->parent_id, 'count' => $this->count, 'order' => $this->order]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'excerpt', $this->excerpt]); return $dataProvider; }
public function actionIndex() { $searchModel = new CourseSearch(); $params = Yii::$app->request->queryParams; //分类 empty($params['slug']) ?: ($params['CourseSearch']['slug'] = $params['slug']); if (isset($params['slug'])) { $courseTerm = CourseTerms::findOne(['slug' => $params['slug']]); $courseTerm ? $params['CourseSearch']['course_terms'] = $courseTerm->id : ''; } //排序 empty($params['sort']) ? '' : ''; // $dataProvider = $searchModel->search($params); $sort = $dataProvider->getSort(); $sort->attributes = array_merge($sort->attributes, ['new' => ['asc' => ['created_at' => SORT_DESC]], 'hot' => ['asc' => ['created_at' => SORT_DESC]], 'rec' => ['asc' => ['create_at' => SORT_DESC]]]); return $this->render('index', ['searchModel' => $searchModel, 'sorts' => $this->sorts, 'dataProvider' => $dataProvider]); }
/** * @return \yii\db\ActiveQuery */ public function getCourseTerms() { return $this->hasOne(CourseTerms::className(), ['id' => 'course_terms']); }
?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'content')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'video_url')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'course_terms')->widget(Select2::classname(), ['data' => CourseTerms::getTermsArray(), 'options' => ['placeholder' => '选择一个分类']]); ?> <?php echo $form->field($model, 'is_rec')->dropDownList($model->recValues()); ?> <?php echo $form->field($model, 'excerpt')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'image')->textInput(['maxlength' => true]); ?> <div class="form-group"> <?php
public function run() { $slug = Yii::$app->request->get('slug'); $terms = CourseTerms::getTermsByOrder(); return $this->render('term', ['terms' => $terms, 'current' => $slug]); }