public function actionIndex() { $this->needAuthenticate(); $pageId = Param::post('page-edit-id', false)->asInteger(false); $name = Param::post('page-edit-name')->noEmpty('Поле "Наименование" должно быть заполнено.')->asString(); $description = Param::post('page-edit-description')->asString(); $content = Param::post('page-edit-content')->asString(); $active = (bool) Param::post('page-edit-active')->exists(); if (!SCMSNotificationLog::instance()->hasProblems()) { /** @var Page $oPage */ $oPage = DataSource::factory(Page::cls(), $pageId == 0 ? null : $pageId); $oPage->name = $name; $oPage->description = $description; $oPage->content = $content; $oPage->active = $active; if (!$oPage->getPrimaryKey()) { $oPage->deleted = false; } $oPage->commit(); SCMSNotificationLog::instance()->pushMessage("Страница \"{$oPage->name}\" успешно " . ($pageId == 0 ? 'добавлена' : 'отредактирована') . '.'); $redirect = ''; if (Param::post('page-edit-accept', false)->exists()) { $redirect = '/admin/modules/pages/'; } elseif ($pageId == 1) { $redirect = "/admin/modules/pages/edit/?id={$oPage->getPrimaryKey()}"; } $this->Response->send($redirect); } else { $this->Response->send(); } }
public function actionPageById($id) { $page = Page::findByPK($id); if (empty($page)) { throw new E404Exception(); } $this->data->page = $page; }
/** * Deletes an existing Url model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { try { $this->findModel($id)->delete(); } catch (yii\db\IntegrityException $e) { $page = Page::findOne(['url' => $id]); return $this->render('integrityException', ['exep' => $e, 'page' => $page]); } return $this->redirect(['index']); }
public function actionIndex($hrurl) { $url = Url::find()->byUrl($hrurl); if (!$url) { throw new NotFoundHttpException(); } $model = Page::findOne(['url' => $url->id]); if (!$model) { throw new NotFoundHttpException(); } return $this->render('index', ['hrurl' => $hrurl, 'url' => $url, 'model' => $model]); }
public function actionIndex() { $view = new ViewPage(); if ($this->page_id != 0) { /** @var Page $oPage */ $oPage = DataSource::factory(Page::cls(), $this->page_id); $view->page = $oPage; $view->render(); } else { echo 'Страница не назначена.'; } }
/** * 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]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'url' => $this->url]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionIndex() { $this->needAuthenticate(); $pageId = Param::get('id')->noEmpty('Не задан обязательный параметр.')->asInteger(true, 'Параметр должен быть числом.'); /** @var Page $oPage */ $oPage = DataSource::factory(Page::cls(), $pageId); if (is_null($oPage) || !$oPage->getPrimaryKey()) { SCMSNotificationLog::instance()->pushError('Статическая страница не найдена.'); } else { SCMSNotificationLog::instance()->pushMessage("Страница \"{$oPage->name}\" успешно удалена."); $oPage->deleted = true; $oPage->commit(); } $this->Response->send(); }
public function actionIndex() { $this->needAuthenticate(); $pageId = Param::get('id', false)->asInteger(false); /** @var Page $oPage */ $oPage = is_null($pageId) ? null : DataSource::factory(Page::cls(), $pageId); $view = new ViewEditForm(); $view->page = $oPage; // Подготовка хлебных крошек $viewBreadcrumbs = new ViewBreadcrumbs(); $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Статичные страницы', '/modules/pages')]; if ($oPage !== null) { $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oPage->name}\"", ''); } else { $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb('Добавление новой статичной страницы', ''); } $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs); $this->Frame->bindView('content', $view); $this->Frame->render(); }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'content')->widget(TinyMCE::className()); ?> <?php if ($model->url !== null) { $pages = Page::find()->where(['!=', 'url', $model->url])->all(); } else { $pages = Page::find()->all(); } $usedUrlsIds = array_map(function ($page) { return $page->url; }, $pages); ?> <?php echo $form->field($model, 'url')->widget(Select2Widget::className(), ['items' => ArrayHelper::map(Url::find()->where(['not in', 'id', $usedUrlsIds])->all(), 'id', 'url')]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getPages() { return $this->hasMany(Page::className(), ['url' => 'id']); }
public function actionMoveAfter($id, $to) { try { $item = Page::findByPK($id); if (empty($item)) { throw new Exception('Source element does not exist'); } $destination = Page::findByPK($to); if (empty($destination)) { throw new Exception('Destination element does not exist'); } $item->insertAfter($destination); $this->data->result = true; } catch (Exception $e) { $this->data->result = false; $this->data->error = $e->getMessage(); } }
/** * Finds the Page model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Page the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Page::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }