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. 42
      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 core\forms\auth\LoginForm;
use yii\filters\AccessControl;
use DomainException;
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);
return $this->goBack();
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
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\web\Controller;
use yii\web\NotFoundHttpException;
use DomainException;
use yii\web\Response;
use RuntimeException;
use Yii;
class MenuController extends Controller
@ -70,7 +73,9 @@ class MenuController extends Controller
$menus = []; // menu list
$menu_records = Menu::find()->all();
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();
@ -105,7 +110,7 @@ class MenuController extends Controller
$menu = $this->menu_service->create($form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
@ -126,7 +131,7 @@ class MenuController extends Controller
$this->menu_service->edit($menu->id, $form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
@ -142,7 +147,7 @@ class MenuController extends Controller
{
try {
$this->menu_service->remove($id);
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
@ -159,7 +164,7 @@ class MenuController extends Controller
$this->menu_item_service->edit($item->id, $form);
return $this->redirect(['index', 'id' => $item->menu_id]);
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
@ -170,7 +175,7 @@ class MenuController extends Controller
public function actionDeleteMenuItem()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
Yii::$app->response->format = Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$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'));
return ['result' => 'success'];
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
@ -191,7 +196,7 @@ class MenuController extends Controller
public function actionSaveMenuItems()
{
$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) {
try {
$order = [];
@ -203,7 +208,7 @@ class MenuController extends Controller
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved'));
return ['result' => 'success'];
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
@ -231,7 +236,7 @@ class MenuController extends Controller
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_item_service->create($form);
} catch (\DomainException $e) {
} catch (DomainException $e) {
Yii::$app->errorHandler->logException($e);
}
}

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

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

Loading…
Cancel
Save