Explorar el Código

Erreur 404 producteurs

refactoring
keun hace 6 años
padre
commit
273ebc3d8f
Se han modificado 6 ficheros con 51 adiciones y 32 borrados
  1. +13
    -3
      frontend/controllers/SiteController.php
  2. +17
    -0
      frontend/views/site/error-404-producer.php
  3. +1
    -1
      producer/config/main.php
  4. +1
    -6
      producer/controllers/ProducerBaseController.php
  5. +16
    -4
      producer/controllers/SiteController.php
  6. +3
    -18
      producer/views/site/error.php

+ 13
- 3
frontend/controllers/SiteController.php Ver fichero

@@ -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() {


+ 17
- 0
frontend/views/site/error-404-producer.php Ver fichero

@@ -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("&lt; Retour à l'accueil", ['site/index']) ?> - <?= Html::a("Liste des producteurs", ['site/producers']) ?></p>
</div>

+ 1
- 1
producer/config/main.php Ver fichero

@@ -24,7 +24,7 @@ return [
],
],
'errorHandler' => [
'errorAction' => 'producer/error',
'errorAction' => 'site/error',
],
'assetManager' => [
'bundles' => [

+ 1
- 6
producer/controllers/ProducerBaseController.php Ver fichero

@@ -14,12 +14,7 @@ class ProducerBaseController extends CommonController {
}
public function actions() {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
return [];
}
public function getProducer() {

+ 16
- 4
producer/controllers/SiteController.php Ver fichero

@@ -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

+ 3
- 18
producer/views/site/error.php Ver fichero

@@ -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>

Cargando…
Cancelar
Guardar