Example #1
1
 public function parseRequest($manager, $request)
 {
     $result = parent::parseRequest($manager, $request);
     if (isset($result[1]) && $result[1]['route']) {
         $route = $result[1]['route'];
         $page = Page::getDb()->cache(function () use($route) {
             return Page::find()->where(['route' => $route])->one();
         });
         if ($page) {
             return [$this->route, ['route' => $route]];
         }
     }
     return false;
 }
Example #2
0
 /**
  * Creates a new Page model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /** @var Page $model */
     $model = Yii::createObject(Page::className());
     if ($model->loadWithRelations(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function beforeAction($action)
 {
     if (!Yii::$app->request->isAjax) {
         $url = '/' . Yii::$app->request->pathInfo;
         /** @var Page $page */
         $page = Page::find()->byRoute($url)->one();
         if ($page !== null) {
             $view = $action->controller->view;
             $page->registerMetaTags($view);
             $view->params['cms.page'] = $page;
         }
     }
     return parent::beforeAction($action);
 }
Example #4
0
 public function generate()
 {
     $selectedPages = Page::find()->where(['id' => $this->pages])->all();
     $time = (new \DateTime())->getTimestamp();
     $pages = [];
     foreach ($selectedPages as $page) {
         $meta = serialize($page->meta);
         $offset = "\n\t\t\t";
         $columns = "[{$offset}'route' => '{$page->route}'," . "{$offset}'title' => '{$page->title}'," . "{$offset}'layout' => '{$page->layout}'," . "{$offset}'content' => '{$page->content}'," . "{$offset}'type' => {$page->type}," . "{$offset}'meta' => '{$meta}'," . "{$offset}'created_at' => {$time}," . "{$offset}'updated_at' => {$time},{$offset}]";
         $pages[] = ['columns' => $columns];
     }
     $files = [];
     $name = 'm' . gmdate('ymd_Hi') . '00_insert_cms_pages';
     $code = $this->render('migration.php', ['name' => $name, 'pages' => $pages, 'createdAt' => $time]);
     $files[] = new CodeFile(Yii::getAlias($this->path) . '/' . $name . '.php', $code);
     return $files;
 }
Example #5
0
 public function run()
 {
     if (($route = Yii::$app->request->getQueryParam('route')) == null) {
         throw new NotFoundHttpException(Yii::t('cms', 'Page not found.'));
     }
     $page = Page::getDb()->cache(function () use($route) {
         return Page::find()->byRoute($route)->one();
     }, null, new TagDependency(['tags' => 'cms.page.' . $route]));
     if (!isset($page)) {
         throw new NotFoundHttpException(Yii::t('cms', 'Page not found.'));
     }
     if ($page->layout) {
         $this->controller->layout = $page->layout;
     }
     if ($page->type == Page::TYPE_CONTENT) {
         $this->view = 'content-view';
     }
     $result = $this->controller->render($this->view, ['page' => $page]);
     //@TODO add tag dependency by blocks
     return $result;
 }
Example #6
0
 /**
  * @return $this
  */
 public function getPages()
 {
     return $this->hasMany(Page::className(), ['id' => 'page_id'])->viaTable(PageHasBlock::tableName(), ['block_id' => 'id']);
 }
Example #7
0
?>
" style="display: none">
                <?php 
echo $this->render('_blocks', ['model' => $model]);
?>
            </div>

        </div>

        <div class="col-md-12">
            <h4><?php 
echo Yii::t('cms', 'Meta Tags');
?>
</h4>
            <?php 
echo $form->field($model, 'meta')->widget(MultipleInput::className(), ['columns' => [['name' => 'name', 'title' => Yii::t('cms', 'Name'), 'type' => 'dropDownList', 'items' => call_user_func([Page::getDefinitionClass(), 'getMetaTypesList'])], ['name' => 'content', 'title' => Yii::t('cms', 'Content')]]])->label(false);
?>
        </div>
    </div>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('cms', 'Create') : Yii::t('cms', 'Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>