/** * @param $id * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionUpdate($id) { $categories = WordsCategory::find()->all(); $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
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]); } }