public function beforeAction($action) { if (parent::beforeAction($action)) { //menu $id = isset($_GET['id']) ? $_GET['id'] : 0; $rootId = $id > 0 ? BlogCatalog::getRootCatalogId($id, BlogCatalog::find()->all()) : 0; $allCatalog = BlogCatalog::findAll(['parent_id' => 0]); 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(['/blog/default/catalog/', 'id' => $catalog->id, 'surname' => $catalog->surname]); } if (!empty($item)) { array_push($this->mainMenu, $item); } } Yii::$app->params['mainMenu'] = $this->mainMenu; return true; // or false if needed } else { return false; } }
/** * Lists all BlogCatalog models. * @return mixed */ public function actionIndex() { //if(!Yii::$app->user->can('readPost')) throw new HttpException(403, 'No Auth'); $searchModel = new BlogCatalogSearch(); $dataProvider = BlogCatalog::get(0, BlogCatalog::find()->all()); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlogCatalog::find(); $query->orderBy(['sort_order' => SORT_ASC, 'create_time' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'is_nav' => $this->is_nav, 'sort_order' => $this->sort_order, 'page_size' => $this->page_size, 'status' => $this->status, 'create_time' => $this->create_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'surname', $this->surname])->andFilterWhere(['like', 'banner', $this->banner])->andFilterWhere(['like', 'template', $this->template])->andFilterWhere(['like', 'redirect_url', $this->redirect_url]); return $dataProvider; }
use funson86\blog\models\BlogCatalog; use kartik\markdown\MarkdownEditor; use mihaildev\ckeditor\CKEditor; /* @var $this yii\web\View */ /* @var $model backend\modules\blog\models\BlogPost */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="blog-post-form"> <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-5\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-2 control-label']]]); ?> <?php echo $form->field($model, 'catalog_id')->dropDownList(ArrayHelper::map(BlogCatalog::get(0, BlogCatalog::find()->all()), 'id', 'str_label')); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 128]); ?> <?php echo $form->field($model, 'brief')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'content')->widget(CKEditor::className(), ['editorOptions' => ['preset' => 'full', 'inline' => false]]); ?> <?php
/** * Normalizes the user-entered tags. */ public static function getArrayCatalog() { return ArrayHelper::map(BlogCatalog::find()->all(), 'id', 'title'); }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use funson86\blog\models\BlogCatalog; use funson86\blog\Module; /* @var $this yii\web\View */ /* @var $model funson86\blog\models\BlogCatalog */ /* @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(BlogCatalog::get(0, BlogCatalog::find()->all()), 'id', 'str_label')); unset($parentCatalog[$model->id]); ?> <div class="blog-catalog-form"> <?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-5\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-2 control-label']]]); ?> <?php echo $form->field($model, 'parent_id')->dropDownList($parentCatalog); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'surname')->textInput(['maxlength' => 128]);