예제 #1
0
 public function search($params)
 {
     $query = WordsCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
예제 #2
0
 public function actionCreate()
 {
     $model = new Words();
     $categories = WordsCategory::find()->all();
     if ($model->load(\Yii::$app->request->post())) {
         if (!$model->save()) {
             var_dump($model->errors);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
예제 #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getChildrens()
 {
     return $this->hasMany(WordsCategory::className(), ['parent_id' => 'id']);
 }
예제 #4
0
파일: Words.php 프로젝트: buuug7/one-words
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(WordsCategory::className(), ['id' => 'category_id']);
 }
예제 #5
0
 /**
  * @param $id
  * @return null|static
  * @throws NotFoundHttpException
  */
 protected function findModel($id)
 {
     if (($model = WordsCategory::findOne($id)) != null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }