/** * @return string */ public static function getPetCatsItems() { $result = []; $petCates = PetCategory::find()->where(['lvl' => 0])->all(); foreach ($petCates as $cat) { $result[] = ['label' => $cat->name, 'url' => ['pest/view', 'slug' => $cat->slug]]; } return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PetCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'lvl' => $this->lvl, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * Updates an existing PetCategory model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $categories = PetCategory::find()->noParents()->andWhere(['not in', 'id', $id])->all(); $categories = ArrayHelper::map($categories, 'id', 'name'); 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]); } }