public function actionCategory($path) { $model = new Category(); $category = $model->findByPath($path); if (!$category) { throw new HttpException('404', 'Категория не найдена'); } $this->layout = '//default'; $items = $category->getItems(['pageSize' => \Yii::$app->params['pageSize']]); $navigation = $category->parentId == 0 ? $category->children() : $category->getSiblings(); return $this->render('category', ['items' => $items, 'model' => $category, 'navigation' => $navigation]); }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['key' => 'id', 'query' => $query, 'pagination' => ['pageSize' => 100]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'dateCreate' => $this->dateCreate, 'visible' => $this->visible, 'parentId' => $this->parentId]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'metaKeywords', $this->metaKeywords])->andFilterWhere(['like', 'metaDescription', $this->metaDescription]); return $dataProvider; }
public function run() { $items = Category::find()->where(['parentId' => 0])->all(); return $this->render('nav', ['items' => $items]); }
public function getCategory() { return $this->hasOne(Category::className(), ['id' => 'parentId']); }