Browse Source

Backend controllers fix

master
Egorka 6 years ago
parent
commit
f5ed9e20b9
  1. 3
      backend/controllers/AuthController.php
  2. 25
      backend/controllers/MenuController.php
  3. 14
      common/modules/pages/views/page/view.php

3
backend/controllers/AuthController.php

@ -9,6 +9,7 @@ use yii\web\Controller;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use core\forms\auth\LoginForm; use core\forms\auth\LoginForm;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use DomainException;
class AuthController extends Controller class AuthController extends Controller
{ {
@ -72,7 +73,7 @@ class AuthController extends Controller
Yii::$app->user->login(new Identity($user), $form->rememberMe ? 3600 * 24 * 30 : 0); Yii::$app->user->login(new Identity($user), $form->rememberMe ? 3600 * 24 * 30 : 0);
return $this->goBack(); return $this->goBack();
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }

25
backend/controllers/MenuController.php

@ -19,6 +19,9 @@ use yii\filters\VerbFilter;
use yii\helpers\Json; use yii\helpers\Json;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use DomainException;
use yii\web\Response;
use RuntimeException;
use Yii; use Yii;
class MenuController extends Controller class MenuController extends Controller
@ -70,7 +73,9 @@ class MenuController extends Controller
$menus = []; // menu list $menus = []; // menu list
$menu_records = Menu::find()->all(); $menu_records = Menu::find()->all();
foreach ($menu_records as $menu_record) { foreach ($menu_records as $menu_record) {
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name; $menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name
? $menu_record->translation->name
: $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name;
} }
$form = new MenuSelectForm(); $form = new MenuSelectForm();
@ -105,7 +110,7 @@ class MenuController extends Controller
$menu = $this->menu_service->create($form); $menu = $this->menu_service->create($form);
return $this->redirect(['index', 'id' => $menu->id]); return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
@ -126,7 +131,7 @@ class MenuController extends Controller
$this->menu_service->edit($menu->id, $form); $this->menu_service->edit($menu->id, $form);
return $this->redirect(['index', 'id' => $menu->id]); return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
@ -142,7 +147,7 @@ class MenuController extends Controller
{ {
try { try {
$this->menu_service->remove($id); $this->menu_service->remove($id);
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
@ -159,7 +164,7 @@ class MenuController extends Controller
$this->menu_item_service->edit($item->id, $form); $this->menu_item_service->edit($item->id, $form);
return $this->redirect(['index', 'id' => $item->menu_id]); return $this->redirect(['index', 'id' => $item->menu_id]);
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
@ -170,7 +175,7 @@ class MenuController extends Controller
public function actionDeleteMenuItem() public function actionDeleteMenuItem()
{ {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; Yii::$app->response->format = Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
try { try {
$id = Yii::$app->request->post('id'); $id = Yii::$app->request->post('id');
@ -180,7 +185,7 @@ class MenuController extends Controller
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted')); Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted'));
return ['result' => 'success']; return ['result' => 'success'];
} catch (\RuntimeException $e) { } catch (RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()]; return ['result' => 'error', 'message' => $e->getMessage()];
} }
} }
@ -191,7 +196,7 @@ class MenuController extends Controller
public function actionSaveMenuItems() public function actionSaveMenuItems()
{ {
$json = Yii::$app->request->post('json'); $json = Yii::$app->request->post('json');
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; Yii::$app->response->format = Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
try { try {
$order = []; $order = [];
@ -203,7 +208,7 @@ class MenuController extends Controller
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved')); Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved'));
return ['result' => 'success']; return ['result' => 'success'];
} catch (\RuntimeException $e) { } catch (RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()]; return ['result' => 'error', 'message' => $e->getMessage()];
} }
} }
@ -231,7 +236,7 @@ class MenuController extends Controller
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->menu_item_service->create($form); $this->menu_item_service->create($form);
} catch (\DomainException $e) { } catch (DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
} }
} }

14
common/modules/pages/views/page/view.php

@ -15,12 +15,12 @@ foreach ($page->parents as $parent) {
$this->params['breadcrumbs'][] = ['label' => $parent->title, 'url' => ['view', 'id' => $parent->id]]; $this->params['breadcrumbs'][] = ['label' => $parent->title, 'url' => ['view', 'id' => $parent->id]];
} }
} }
$this->params['breadcrumbs'][] = $page->title; $this->params['breadcrumbs'][] = $page->translation->title;
?> ?>
<article class="page-view"> <article class="page-view">
<h1><?= Html::encode($page->title) ?></h1> <h1><?= Html::encode($page->translation->title) ?></h1>
<!-- <!--
< ?= preg_replace('/[?= (*.) ?]/m', '', Yii::$app->formatter->asHtml($page->content, [ < ?= preg_replace('/[?= (*.) ?]/m', '', Yii::$app->formatter->asHtml($page->content, [
'Attr.AllowedRel' => array('nofollow'), 'Attr.AllowedRel' => array('nofollow'),
'HTML.SafeObject' => true, 'HTML.SafeObject' => true,
@ -39,12 +39,12 @@ $this->params['breadcrumbs'][] = $page->title;
'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', 'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%',
])) ?> --> ])) ?> -->
<?= $page->content(Yii::$app->formatter->asHtml($page->content, [ <?= $page->content(Yii::$app->formatter->asHtml($page->translation->content, [
'Attr.AllowedRel' => array('nofollow'), 'Attr.AllowedRel' => ['nofollow'],
'HTML.SafeObject' => true, 'HTML.SafeObject' => true,
'Output.FlashCompat' => true, 'Output.FlashCompat' => true,
'HTML.SafeIframe' => true, 'HTML.SafeIframe' => true,
'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', 'URI.SafeIframeRegexp' => '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%',
]))?> ])) ?>
</article> </article>

Loading…
Cancel
Save