Example #1
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.');
     }
 }
Example #2
0
 protected function findModelBySlug($slug)
 {
     if (($model = Page::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException();
     }
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => 3]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #4
0
 public function actionSitemap()
 {
     if (Yii::$app->request->isPost) {
         $sitemap = new Sitemap(Yii::getAlias('@webroot/sitemap.xml'));
         $sitemap->addItem(Url::to(['/main/default/index'], true), time(), Sitemap::WEEKLY, 1);
         $sitemap->addItem(Url::to(['/main/contact/index'], true), time(), Sitemap::MONTHLY, 1);
         $pages = Page::findAll(['status' => 1]);
         foreach ($pages as $page) {
             $sitemap->addItem(Url::to(['/page/node/view', 'slug' => $page->slug], true), $page->updated_at, Sitemap::MONTHLY, 1);
         }
         $posts = Post::findAll(['status' => 1]);
         foreach ($posts as $post) {
             $sitemap->addItem(Url::to(['/post/node/view', 'slug' => $post->slug], true), $post->updated_at, Sitemap::NEVER, 0.8);
         }
         $sitemap->write();
         Yii::$app->session->setFlash('success', "Файл sitemap.xml успешно обновлен.");
         Yii::$app->request->referrer ? $this->redirect(Yii::$app->request->referrer) : $this->goHome();
     } else {
         throw new NotFoundHttpException('Страница не найдена');
     }
 }
Example #5
0
use yii\widgets\Pjax;
use app\modules\page\models\backend\Page;
use app\widgets\grid\SetColumn;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\page\models\backend\search\PageSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Страницы';
$this->params['breadcrumbs'][] = $this->title;
?>

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p class="pull-left">
        <?php 
echo Html::a('<i class="material-icons">add</i> Добавить страницу', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

<?php 
Pjax::begin(['enablePushState' => false]);
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'contentOptions' => ['class' => 'check-column']], ['attribute' => 'title', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    /** @var \app\modules\page\models\backend\Page $model */
    return Html::a(Html::encode($model->title), ['/page/node/view', 'slug' => $model->slug]);
}], ['attribute' => 'updated_at', 'format' => 'datetime', 'contentOptions' => ['class' => 'at-column']], ['class' => SetColumn::className(), 'filter' => Page::getStatusesArray(), 'attribute' => 'status', 'name' => 'statusName', 'cssCLasses' => [Page::STATUS_ACTIVE => 'success', Page::STATUS_WAIT => 'warning'], 'contentOptions' => ['class' => 'status-column']], ['class' => 'app\\widgets\\grid\\ActionColumn', 'buttons' => ['view' => function ($url, $model, $key) {
    /** @var \app\modules\page\models\backend\Page $model */
    return Html::a('<i class="material-icons">visibility</i>', ['/page/node/view', 'slug' => $model->slug]);
}]]]]);
Pjax::end();