yii2 404 error handling
yii2 404 error handling
The frontend and backend configuration methods are the same. The frontend is demonstrated here
1. First go to the frontend\config folder of the yii framework, there is a main.php file in it, open it for editing, and modify the controller name and method name:
'errorHandler' => [ 'errorAction' => 'common/error', ],
Recommended learning: yii framework
As shown in the picture:
2. Then go to controllers to create your controller and write the following code:
/** * 404友好页面 */ public function actions(){ return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, , ]; }
As shown:
3. Finally create your view on the V layer (here is error.php):
<?php $this->context->layout = false; //不加载公共样式 ?> <!DOCTYPE html> <html> <head> <title>404错误,您所访问的页面不存在!</title> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css"/> <link rel="stylesheet" href="css/base.css"/> </head> <body> <div id="errorpage"> <div class="tfans_error"> <div class="logo"></div> <div class="errortans clearfix"> <div class="e404"></div> <p><b>出错啦!</b></p> <p>您访问的页面不存在</p> <div class="bt" ><a href="?r=index/index">返回首页</a></div> </div> </div> </div> </body> </html>
As shown :
##
The above is the detailed content of yii2 404 error handling. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses best practices for deploying Yii applications in cloud-native environments, focusing on scalability, reliability, and efficiency through containerization, orchestration, and security measures.

The article discusses key considerations for using Yii in serverless architectures, focusing on statelessness, cold starts, function size, database interactions, security, and monitoring. It also covers optimization strategies and potential integrati

The article discusses strategies for testing Yii applications using Codeception, focusing on using built-in modules, BDD, different test types, mocking, CI integration, and code coverage.

Yii's built-in testing framework enhances application testing with features like PHPUnit integration, fixture management, and support for various test types, improving code quality and development practices.

The article discusses tools for monitoring and profiling Yii application performance, including Yii Debug Toolbar, Blackfire, New Relic, Xdebug, and APM solutions like Datadog and Dynatrace.

The article discusses implementing real-time data synchronization using Yii and WebSockets, covering setup, integration, and best practices for performance and security.

The article discusses key considerations for deploying Yii applications in production, focusing on environment setup, configuration management, performance optimization, security, logging, monitoring, deployment strategies, and backup/recovery plans.

The article discusses Yii's benefits for SaaS development, focusing on performance, security, and rapid development features to enhance scalability and reduce time-to-market.
