/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'view' => $this->view, 'position' => $this->position, 'status' => $this->status, 'created' => $this->created, 'updated' => $this->updated]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]); return $dataProvider; }
/** * Updates an existing Pages 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); $statusArray = Pages::getPagesStatusArray(); $categoryArray = Category::getCategoryArray(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'statusArray' => $statusArray, 'categoryArray' => $categoryArray]); } }
/** * @return Категория страницы. */ public function getCategory() { return $this->hasOne(Category::className(), ['id' => 'category_id']); }
public static function getMenu($parent_id = null, $level = 0) { if (empty($parent_id)) { $parent_id = null; } $categories = Category::find()->where(['parent_id' => $parent_id])->all(); $list = array(); foreach ($categories as $category) { //$category->title = str_repeat(' - ', $level) . $category->title; //$list[]['label'] = $category->title; //$list[]['alias'] = $category->alias; $list[] = array('label' => $category->title, 'url' => $category->alias); $list = ArrayHelper::merge($list, self::getMenu($category->id, $level + 1)); } return $list; }
/** * 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.'); } }