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; }
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]); } }
/** * @return \yii\db\ActiveQuery */ public function getChildrens() { return $this->hasMany(WordsCategory::className(), ['parent_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(WordsCategory::className(), ['id' => 'category_id']); }
/** * @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.'); } }