/** * Lists all CmsCatalog models. * @return mixed */ public function actionIndex() { //if(!Yii::$app->user->can('viewYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth')); $searchModel = new CmsCatalogSearch(); $dataProvider = CmsCatalog::get(0, CmsCatalog::find()->asArray()->all()); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function beforeAction($action) { if (parent::beforeAction($action)) { //menu $id = Yii::$app->request->get('id'); $rootId = $id ? CmsCatalog::getRootCatalogId($id, CmsCatalog::find()->asArray()->all()) : 0; $allCatalog = CmsCatalog::find()->where(['status' => Status::STATUS_ACTIVE, 'is_nav' => CmsCatalog::IS_NAV_YES])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all(); foreach ($allCatalog as $catalog) { $item = ['label' => $catalog->title, 'active' => $catalog->id == $rootId]; if ($catalog->redirect_url) { // redirect to other site $item['url'] = $catalog->redirect_url; } else { $item['url'] = Yii::$app->getUrlManager()->createUrl(['/cms/default/' . $catalog->page_type . '/', 'id' => $catalog->id, 'surname' => $catalog->surname]); } if (!empty($item)) { array_push($this->mainMenu, $item); } } Yii::$app->params['mainMenu'] = $this->mainMenu; // sub menu 2 if (isset(Yii::$app->params['mainMenu2'])) { $allCatalog = CmsCatalog::get(0, CmsCatalog::find()->asArray()->all()); foreach ($allCatalog as $catalog) { $item = ['label' => $catalog['title'], 'active' => $catalog['id'] == $id]; if ($catalog['redirect_url']) { // redirect to other site $item['url'] = $catalog['redirect_url']; } else { $item['url'] = $catalog['parent_id'] != 0 ? Yii::$app->getUrlManager()->createUrl(['/cms/default/' . $catalog['page_type'] . '/', 'id' => $catalog['id'], 'surname' => $catalog['surname']]) : '#'; } if ($catalog['parent_id'] == 0) { $this->mainMenu2[$catalog['id']] = $item; } else { if (isset($this->mainMenu2[$catalog['parent_id']])) { $this->mainMenu2[$catalog['parent_id']]['items'][$catalog['id']] = $item; } } } Yii::$app->params['mainMenu2'] = $this->mainMenu2; } return true; // or false if needed } else { return false; } }
use yii\helpers\ArrayHelper; use clh021\cms\models\CmsCatalog; use mihaildev\ckeditor\CKEditor; /* @var $this yii\web\View */ /* @var $model app\models\CmsShow */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="cms-show-form"> <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-5\">{input}</div>\n<div class=\"col-lg-2\">{hint}{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label']]]); ?> <?php echo $form->field($model, 'catalog_id')->dropDownList(ArrayHelper::map(CmsCatalog::get(0, CmsCatalog::find()->where(['status' => \clh021\blog\models\Status::STATUS_ACTIVE, 'page_type' => CmsCatalog::PAGE_TYPE_LIST])->asArray()->all()), 'id', 'label')); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'surname')->textInput(['maxlength' => 128]); ?> <?php echo $form->field($model, 'brief')->textInput(['maxlength' => 1022]); ?> <?php
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use clh021\cms\models\CmsCatalog; use clh021\cms\Module; use mihaildev\ckeditor\CKEditor; /* @var $this yii\web\View */ /* @var $model app\models\CmsCatalog */ /* @var $form yii\widgets\ActiveForm */ //fix the issue that it can assign itself as parent $parentCatalog = ArrayHelper::merge([0 => Module::t('blog', 'Root Catalog')], ArrayHelper::map(CmsCatalog::get(0, CmsCatalog::find()->asArray()->all()), 'id', 'label')); unset($parentCatalog[$model->id]); ?> <div class="cms-catalog-form"> <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-5\">{input}</div>\n<div class=\"col-lg-2\">{hint}{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label']]]); ?> <?php echo $form->field($model, 'parent_id')->dropDownList($parentCatalog); ?> <?php echo $form->field($model, 'page_type')->dropDownList(CmsCatalog::getCatalogPageTypeLabels())->hint(Module::t('cms', 'Page need content')); ?> <?php