2016-06-08 5 views
0
Arbeits

Für Fehler Aktion Einstellung habe ich diesen Code in meinem ControllerEinstellungsfehler Aktion Layout in yii2 nicht

public function beforeAction($action) { 
    if ($action->id == 'error') 
     $this->layout = 'iframe-main.php'; 

    $this->enableCsrfValidation = false; 
    return parent::beforeAction($action); 
} 

Aber nicht working.Error Layout angezeigt wird dies in Standard-Layout

+0

Ähnliche Fragen hier: http://stackoverflow.com/questions/27573826/how-to-set-layout-for-errorhandler-dynamically-without-module – robsch

Antwort

2

Versuchen:

public function beforeAction($action) { 
    if (parent::beforeAction($action)) { 
     // change layout for error action 
     if ($action->id=='error') $this->layout ='iframe-main'; 
     return true; 
    } else { 
     return false; 
    } 
} 
+0

funktioniert nicht !! @ Jithin – Jackhad

+0

ahh..its mein Fehler .. Ich füge das in meinem Controller anstelle von sitecontroller.php.Working gut! Vielen Dank!! :) – Jackhad

0

In Ihrem Actionerror() von SiteController einfach den Namen Standard-Layout

hinzufügen
+0

Im mit Yii2.Es wird nicht actionError() – Jackhad

1

zu Ihren Konfigurations hinzufügen:

'components' => ['errorHandler' => [ 
     'errorAction' => 'site/error', 
    ], 

Controller erstellen, falls nicht vorhanden ist: SiteController.php mit Inhalt:

namespace app\controllers; 

use Yii; 
use yii\web\Controller; 

class SiteController extends Controller 
{ 
    public function actionError() 
    { 
     $exception = Yii::$app->errorHandler->exception; 
     if ($exception !== null) { 
      $this->layout = 'yourNewLayout'; 
      return $this->render('error', ['exception' => $exception]); 
     } 
    } 
} 

und einfachste Ansicht site/error.php:

<?php 
    use yii\helpers\Html; 
?> 
<div class="site-error"> 
     <?= Html::encode($exception->getMessage()) ?> 
</div> 

Getestet auf Yii2. Weitere Informationen finden Sie in der Dokumentation http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html#using-error-handler

Verwandte Themen