コード例 #1
0
ファイル: MenuHelper.php プロジェクト: kartrez/pitomec
 /**
  * @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;
 }
コード例 #2
0
ファイル: PetCategorySearch.php プロジェクト: kartrez/pitomec
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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]);
     }
 }