2

...HttpExceptionアプリケーションのログインには、ロギング エラーをスローする次のコードがあります。

// common/models/LoginForm.php which is called from the backend SiteController actionLogin method as $model = new LoginForm();

public function loginAdmin()
    {
      //die($this->getUser()->getRoleValue()."hhh");
      if ($this->getUser()->getRoleValue() >= ValueHelpers::getRoleValue('Admin') && $this->getUser()->getStatusValue() == ValueHelpers::getStatusValue('Active')){
        if ($this->validate()){
          return \Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30:0);         
        }
        else{
          throw new \yii\web\NotFoundHttpException('Incorrect Password or Username.');

        }       
      }
      else{
        throw new \yii\web\ForbiddenHttpException('Insufficient privileges to access this area.');
      }
    }

NotFoundHttpException正常に動作していますが、とのそれぞれでレンダリングされたページをカスタマイズしたいと思いますForbiddenHttpExceptionYii2 apiを検索して、オブジェクトの構成でビューを定義する可能性のあるパラメーターを見つけようとしましたが、それが見つかりませんでした。では、例外のビューをカスタマイズする方法はありますか?

4

2 に答える 2

1

こちらをご覧ください https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/controllers/SiteController.php

外部アクションを使用してエラーを処理していることがわかります

/**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

デフォルトのものを拡張し、Yii のデフォルトのものの代わりに独自の ErrorAction ファイルを使用する独自の ErrorAction ファイルを作成するか、そのアクションをコメントアウトして通常の actionError を作成し、そこに配置することができます。

于 2015-02-04T23:38:19.393 に答える