瀏覽代碼

Erreur 404 producteurs

refactoring
keun 6 年之前
父節點
當前提交
273ebc3d8f
共有 6 個檔案被更改,包括 51 行新增32 行删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

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

+ 1
- 6
producer/controllers/ProducerBaseController.php 查看文件

@@ -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 查看文件

@@ -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 查看文件

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

Loading…
取消
儲存