コード例 #1
0
 /**
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionMain()
 {
     /* @var $module \pavlinter\admpages\Module */
     $module = Module::getInstance();
     /* @var $model \pavlinter\admpages\models\Page */
     $model = $module->manager->createPageQuery('get', null, ['where' => ['type' => 'main'], 'orderBy' => ['weight' => SORT_ASC]]);
     if (!$model) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if (isset($module->pageRedirect[$model->layout])) {
         $params = $module->pageRedirect[$model->layout];
         if ($params instanceof \Closure) {
             $params = call_user_func($params, $model, $module);
         } else {
             $params['modelPage'] = $model;
         }
         $route = ArrayHelper::remove($params, 0);
         $parts = Yii::$app->createController($route);
         if (is_array($parts)) {
             /* @var $controller Controller */
             list($controller, $actionID) = $parts;
             $result = $controller->runAction($actionID, $params);
         } else {
             $id = Yii::$app->getUniqueId();
             throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
         }
         if ($result instanceof \yii\web\Response) {
             return $result;
         } else {
             $response = Yii::$app->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     }
     return $this->render('@vendor/pavlinter/yii2-adm-pages/admpages/views/default/' . $model->layout, ['model' => $model]);
 }
コード例 #2
0
ファイル: main.php プロジェクト: pavlinter/yii2-app-core
<?php

use app\assets_b\AppAsset;
use pavlinter\admpages\Module;
/* @var $this yii\web\View */
/* @var $model \pavlinter\admpages\models\Page */
Module::getInstance()->layout = Module::getInstance()->pageLayout;
$this->title = $model->title;
$appAsset = AppAsset::register($this);
Yii::$app->params['html.canonical'] = Yii::$app->homeUrl;
?>
<div class="main-page">
    <h1><?php 
echo $model->title;
?>
</h1>
    <div><?php 
echo $model->text();
?>
</div>
</div>
コード例 #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 string $id
  * @return \pavlinter\admpages\models\Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $model = Module::getInstance()->manager->createPageQuery('find')->with(['translations'])->where(['id' => $id])->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: index.php プロジェクト: pavlinter/yii2-adm-pages
    $url = ['delete', 'id' => $model->id];
    if ($model->id_parent) {
        $url['id_parent'] = $model->id_parent;
    } else {
        $url['id_parent'] = 0;
    }
    return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => Module::t('title', 'Delete', ['dot' => false]), 'data-confirm' => Module::t('', 'Are you sure you want to delete this item?', ['dot' => false]), 'data-method' => 'post', 'data-pjax' => '0']);
}, 'view' => function ($url, $model) {
    if ($model->alias) {
        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $model->url(), ['title' => Module::t('title', 'View', ['dot' => false]), 'data-pjax' => '0', 'target' => '_blank']);
    }
}, 'copy' => function ($url, $model) {
    $url = ['create', 'id' => $model->id];
    if ($model->id_parent) {
        $url['id_parent'] = $model->id_parent;
    } else {
        $url['id_parent'] = 0;
    }
    return Html::a('<span class="fa fa-copy"></span>', $url, ['title' => Module::t('title', 'Copy', ['dot' => false]), 'data-pjax' => '0']);
}, 'subpages' => function ($url, $model) {
    return Html::a('<span class="fa fa-plus-circle"></span>', ['', 'id_parent' => $model->id], ['title' => Module::t('title', 'Sub pages', ['dot' => false]), 'data-pjax' => '0']);
}, 'files' => function ($url, $model) {
    if (!isset(Module::getInstance()->files[$model->type])) {
        return null;
    }
    return Html::a('<span class="fa fa-cloud-download"></span>', ['files', 'id' => $model->id], ['title' => Module::t('title', 'Files', ['dot' => false]), 'data-pjax' => '0']);
}]]]]);
?>

</div>
コード例 #5
0
ファイル: _form.php プロジェクト: pavlinter/yii2-adm-pages
?>

    <div class="row">
        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'id_parent')->widget(\kartik\widgets\Select2::classname(), ['data' => $parentsData, 'options' => ['placeholder' => Module::t('', 'Select ...', ['dot' => false])], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-3">
        <?php 
echo $form->field($model, 'layout')->widget(\kartik\widgets\Select2::classname(), ['data' => Module::getInstance()->pageLayouts]);
?>
        </div>
        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'type')->widget(\kartik\widgets\Select2::classname(), ['data' => Module::getInstance()->pageTypes]);
?>
        </div>

        <div class="col-xs-12 col-sm-6 col-md-3">
            <?php 
echo $form->field($model, 'date')->widget(\kartik\datetime\DateTimePicker::classname(), ['pluginOptions' => ['todayHighlight' => true, 'todayBtn' => true, 'autoclose' => true, 'minuteStep' => 1, 'format' => 'yyyy-mm-dd hh:ii:00']]);
?>
        </div>

    </div>

    <section class="panel adm-langs-panel">
        <header class="panel-heading bg-light">
            <ul class="nav nav-tabs nav-justified text-uc">
                <?php