/** * @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; }
/** * Finds the PetCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PetCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PetCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @inheritdoc */ public function rules() { return [[['name'], 'required'], [['description'], 'string'], [['lvl', 'status'], 'integer'], [['name', 'image_path', 'main_image', 'slug'], 'string', 'max' => 256], [['slug'], 'unique'], [['image_path', 'main_image', 'category_image'], 'safe'], ['parent_id', 'exist', 'targetClass' => PetCategory::className(), 'targetAttribute' => 'id']]; }
/** * @return \yii\db\ActiveQuery */ public function getPetCategory() { return $this->hasOne(PetCategory::className(), ['id' => 'pet_category_id']); }