Yii2 制作一个404页面

我是通过模块的方式添加的。

1.添加模块:

  1. 'site' => [
  2. 'class' => '\fecshop\app\appfront\modules\Site\Module',
  3. ],

2.新建controller方法:

  1. <?php
  2. namespace fecshop\app\appfront\modules\Site\controllers;
  3. use Yii;
  4. use fec\helpers\CModule;
  5. use fecshop\app\appfront\modules\AppfrontController;
  6. class HelperController extends AppfrontController
  7. {
  8. public function actions()
  9. {
  10. return [
  11. 'error' => [
  12. 'class' => 'yii\web\ErrorAction',
  13. ],
  14. 'captcha' => [
  15. 'class' => 'yii\captcha\CaptchaAction',
  16. 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  17. ],
  18. ];
  19. }
  20. }

3.新建view方法

  1. <?php
  2. /* @var $this yii\web\View */
  3. /* @var $name string */
  4. /* @var $message string */
  5. /* @var $exception Exception */
  6. use yii\helpers\Html;
  7. $this->title = $name;
  8. ?>
  9. <div class="site-error">
  10. <h1><?= Html::encode($this->title) ?></h1>
  11. <div class="alert alert-danger">
  12. <?= nl2br(Html::encode($message)) ?>
  13. </div>
  14. <p>
  15. The above error occurred while the Web server was processing your request.
  16. </p>
  17. <p>
  18. Please contact us if you think this is a server error. Thank you.
  19. </p>
  20. </div>

4.设置:(config)

  1. 'errorHandler' => [
  2. 'errorAction' => 'site/helper/error',
  3. ],

这样就添加成功了。

发布于2016年8月4日
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值