예제 #1
0
 public function run()
 {
     $model = new Page();
     $data = $model->getParents();
     $items = [];
     $model->makeTree($data, 0, $items, Page::DIR);
     return $this->render('TreeNavigationView', ['items' => $items]);
 }
 public function actionPage($path = 'index')
 {
     /** @var  $page  Page*/
     $model = new Page();
     $page = $model->findByFullPath($path);
     if (!$page) {
         throw new HttpException('404', 'Страница не найдена');
     }
     $page->imageThemeSet();
     return $this->render('page', ['page' => $page]);
 }
예제 #3
0
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Page::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
 }
예제 #5
0
 public function findByUrl($alias)
 {
     /* @var $model Page */
     $url = $alias;
     $urlList = [];
     $urlCheck = [];
     if (substr_count($url, '/')) {
         $urlList = explode('/', $url);
         $url = array_pop($urlList);
     }
     $model = Page::findOne(['alias' => $url]);
     $parents = $model->parents();
     foreach ($parents as $item) {
         $urlCheck[] = $item->alias;
     }
     if ($urlList == $urlCheck) {
         return $model;
     }
     return null;
 }
예제 #6
0
 public function getCategory()
 {
     return $this->hasOne(Page::className(), ['id' => 'parentId']);
 }