@@ -64,15 +64,25 @@ class SiteController extends FrontendController { | |||
*/ | |||
public function actions() { | |||
return [ | |||
'error' => [ | |||
'class' => 'yii\web\ErrorAction', | |||
], | |||
'captcha' => [ | |||
'class' => 'yii\captcha\CaptchaAction', | |||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | |||
], | |||
]; | |||
} | |||
public function actionError() | |||
{ | |||
$exception = Yii::$app->errorHandler->exception; | |||
if ($exception !== null) { | |||
return $this->render('error', ['exception' => $exception]); | |||
} | |||
if( Yii::$app->getRequest()->getQueryParam('producer_not_found')) { | |||
return $this->render('error-404-producer', ['exception' => $exception]); | |||
} | |||
} | |||
public function actionIndex() { | |||
@@ -0,0 +1,17 @@ | |||
<?php | |||
$this->setTitle('Producteur introuvable') ; | |||
?> | |||
<div class="site-error"> | |||
<h1>Producteur introuvable</h1> | |||
<div class="alert alert-danger"> | |||
Le producteur que vous recherchez est introuvable. | |||
</div> | |||
<p><?= Html::a("< Retour à l'accueil", ['site/index']) ?> - <?= Html::a("Liste des producteurs", ['site/producers']) ?></p> | |||
</div> |
@@ -24,7 +24,7 @@ return [ | |||
], | |||
], | |||
'errorHandler' => [ | |||
'errorAction' => 'producer/error', | |||
'errorAction' => 'site/error', | |||
], | |||
'assetManager' => [ | |||
'bundles' => [ |
@@ -14,12 +14,7 @@ class ProducerBaseController extends CommonController { | |||
} | |||
public function actions() { | |||
return [ | |||
'error' => [ | |||
'class' => 'yii\web\ErrorAction', | |||
], | |||
]; | |||
return []; | |||
} | |||
public function getProducer() { |
@@ -3,7 +3,7 @@ | |||
namespace producer\controllers; | |||
class SiteController extends ProducerBaseController { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
@@ -13,9 +13,6 @@ class SiteController extends ProducerBaseController { | |||
public function actions() { | |||
return [ | |||
'error' => [ | |||
'class' => 'yii\web\ErrorAction', | |||
], | |||
'captcha' => [ | |||
'class' => 'yii\captcha\CaptchaAction', | |||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | |||
@@ -23,6 +20,21 @@ class SiteController extends ProducerBaseController { | |||
]; | |||
} | |||
public function actionError() | |||
{ | |||
$exception = Yii::$app->errorHandler->exception; | |||
if ($exception !== null) { | |||
if($exception->getMessage() == 'Établissement introuvable') { | |||
Yii::$app->getResponse()->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true]))->send(); | |||
return; | |||
} | |||
else { | |||
return $this->render('error', ['exception' => $exception]); | |||
} | |||
} | |||
} | |||
/** | |||
* | |||
* Affiche la page d'accueil des producteurs comprenant une image, une |
@@ -1,22 +1,7 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
/* @var $this yii\web\View */ | |||
/* @var $name string */ | |||
/* @var $message string */ | |||
/* @var $exception Exception */ | |||
$this->title = $name; | |||
?> | |||
<div class="site-error"> | |||
<h1><?= Html::encode($this->title) ?></h1> | |||
<h1>Erreur <?= $exception->statusCode; ?></h1> | |||
<div class="alert alert-danger"> | |||
<?= nl2br(Html::encode($message)) ?> | |||
<?= $exception->getMessage(); ?> | |||
</div> | |||
<p><?= Html::a("Retour à l'accueil", ['site/index']) ?></p> | |||
</div> | |||
</div> |