示例#1
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex($slug = 'index')
 {
     // display home page
     if (empty($slug) || $slug == 'index') {
         $query = Post::find()->where(['status' => Post::STATUS_PUBLISHED]);
         $countQuery = clone $query;
         $pagination = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 5]);
         $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
         return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
     }
     //try to display action from controller
     try {
         return $this->runAction($slug);
     } catch (\yii\base\InvalidRouteException $ex) {
     }
     //try to display static page from datebase
     $page = Page::getDb()->cache(function ($db) use($slug) {
         return Page::findOne(['slug' => $slug, 'status' => Page::STATUS_PUBLISHED]);
     }, 3600);
     if ($page) {
         $pageAction = new PageAction($slug, $this, ['slug' => $slug, 'page' => $page]);
         return $pageAction->run();
     }
     //try to display post from datebase
     $post = Post::getDb()->cache(function ($db) use($slug) {
         return Post::findOne(['slug' => $slug, 'status' => Post::STATUS_PUBLISHED]);
     }, 3600);
     if ($post) {
         $postAction = new PostAction($slug, $this, ['slug' => $slug, 'post' => $post]);
         return $postAction->run();
     }
     //if nothing suitable was found then throw 404 error
     throw new \yii\web\NotFoundHttpException('Page not found.');
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'status' => $this->status, 'comment_status' => $this->comment_status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'revision' => $this->revision]);
     $query->andFilterWhere([$this->published_at_operand ? $this->published_at_operand : '=', 'published_at', $this->published_at ? strtotime($this->published_at) : null]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
示例#3
0
<?php

/* @var $this yii\web\View */
use yeesoft\comments\widgets\Comments;
use yeesoft\page\models\Page;
use yii\helpers\Html;
$this->title = $page->title;
$this->params['breadcrumbs'][] = $page->title;
?>

    <div class="page">
        <h1><?php 
echo Html::encode($page->title);
?>
</h1>
        <div><?php 
echo $page->content;
?>
</div>
    </div>
<?php 
if ($page->comment_status == Page::COMMENT_STATUS_OPEN) {
    ?>
    <?php 
    echo Comments::widget(['model' => Page::className(), 'model_id' => $page->id]);
}
示例#4
0
                <div class="col-sm-6 text-right">
                    <?php 
echo GridPageSize::widget(['pjaxId' => 'page-grid-pjax']);
?>
                </div>
            </div>

            <?php 
Pjax::begin(['id' => 'page-grid-pjax']);
?>

            <?php 
echo GridView::widget(['id' => 'page-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'page-grid', 'actions' => [Url::to(['bulk-activate']) => Yii::t('yee', 'Publish'), Url::to(['bulk-deactivate']) => Yii::t('yee', 'Unpublish'), Url::to(['bulk-delete']) => Yii::t('yii', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/page/default', 'title' => function (Page $model) {
    return Html::a($model->title, ['/page/default/view', 'id' => $model->id], ['data-pjax' => 0]);
}], ['attribute' => 'created_by', 'filter' => User::getUsersList(), 'value' => function (Page $model) {
    return Html::a($model->author->username, ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers'), 'options' => ['style' => 'width:180px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Page::getStatusOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\DateFilterColumn', 'attribute' => 'published_at', 'value' => function (Page $model) {
    return '<span style="font-size:85%;" class="label label-' . (time() >= $model->published_at ? 'primary' : 'default') . '">' . $model->publishedDate . '</span>';
}, 'format' => 'raw', 'options' => ['style' => 'width:150px']]]]);
?>

            <?php 
Pjax::end();
?>
        </div>
    </div>
</div>


示例#5
0
                        <?php 
echo $form->field($model, 'status')->dropDownList(Page::getStatusList());
?>

                        <?php 
if (!$model->isNewRecord) {
    ?>
                            <?php 
    echo $form->field($model, 'created_by')->dropDownList(User::getUsersList());
    ?>
                        <?php 
}
?>

                        <?php 
echo $form->field($model, 'comment_status')->dropDownList(Page::getCommentStatusList());
?>

                        <?php 
echo $form->field($model, 'view')->dropDownList($this->context->module->viewList);
?>

                        <?php 
echo $form->field($model, 'layout')->dropDownList($this->context->module->layoutList);
?>

                    </div>
                </div>
            </div>

        </div>