---
title: "YII2 模块内自定义错误页"
author: "vb2005xu"
date: "2015-11-07T12:17:43Z"
tags: ["Yii"]
categories: ["开源软件"]
slug: "yii2"
draft: false
lastmod: "2015-11-07T12:17:43Z"
id: 2255423
url: "https://vb2005xu.iteye.com/blog/2255423"
---

当前YII框架中把错误异常配置都放置在 web.php 中,对于新增的模块 module 非常不方便,而且文档中基本没有任何教程,此处给大家分享一个方法:

```
<?php

namespace app\modules\cangshu;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\cangshu\controllers';

    public function init()
    {
        parent::init();

        // \Yii::configure($this->module, require(__DIR__ . '/config.php'));
        
        // 自定义错误页
        \Yii::$app->errorHandler->errorAction = 'cangshu/error/view';
    }
}
```

希望对大家有用,更多内容请看我博客: [http://vb2005xu.iteye.com](/)