/** * Create page instance by type. * * @param string $type * @return Page */ public function getPageInstance($type = null) { /** @var \im\base\types\EntityTypesRegister $typesRegister */ $typesRegister = Yii::$app->get('typesRegister'); $class = $type && $typesRegister->hasEntityType($type) ? $typesRegister->getEntityClass($type) : Page::className(); return Yii::createObject(['class' => $class, 'type' => $type]); }
/** * @inheritdoc */ public function init() { parent::init(); $pageClass = Page::className(); if ($this->modelClass != $pageClass && !is_subclass_of($this->modelClass, $pageClass)) { throw new InvalidConfigException("The 'modelClass' property class must be '{$pageClass}' or it's subclass."); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Page::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * @inheritdoc */ protected function getModelClass() { return Page::className(); }
$this->title = Module::t('page', 'Pages'); $this->params['subtitle'] = Module::t('module', 'Pages list'); $this->params['breadcrumbs'][] = $this->title; $gridId = 'pages-grid'; $gridConfig = ['id' => $gridId, 'tableOptions' => ['class' => 'table table-bordered table-hover'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], ['attribute' => 'id', 'filter' => false], 'title', ['attribute' => 'slug', 'format' => 'html', 'value' => function ($model) { return Html::a($model['slug'], ['update', 'id' => $model['id']], ['data-pjax' => 0]); }], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { if ($model->status === $model::STATUS_PUBLISHED) { $class = 'label-success'; } elseif ($model->status === $model::STATUS_UNPUBLISHED) { $class = 'label-warning'; } else { $class = 'label-danger'; } return '<span class="label ' . $class . '">' . $model->getStatus() . '</span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'status', Page::getStatusesList(), ['class' => 'form-control', 'prompt' => Module::t('page', 'Select status')])], ['attribute' => 'created_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'created_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])], ['attribute' => 'updated_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])]]]; $boxButtons = $actions = []; $showActions = false; //if (Yii::$app->user->can('BackendCreatePages')) { $boxButtons[] = '{create}'; //} //if (Yii::$app->user->can('BackendUpdatePages')) { $actions[] = '{update}'; $showActions = $showActions || true; //} //if (Yii::$app->user->can('BackendDeletePages')) { $boxButtons[] = '{batch-delete}'; $actions[] = '{delete}'; $showActions = $showActions || true; //} if ($showActions === true) {
/** * Registers a class definitions in container. */ public function registerDefinitions() { Yii::$container->set(Page::className(), ['as seo' => ['class' => 'im\\seo\\components\\SeoBehavior', 'metaClass' => 'im\\cms\\models\\PageMeta', 'ownerType' => false], 'as template' => ['class' => 'im\\cms\\components\\TemplateBehavior']]); }