Home Backend Development PHP Tutorial Custom error pages and prompt pages in ThinkPHP

Custom error pages and prompt pages in ThinkPHP

Jun 06, 2018 pm 02:22 PM
thinkphp customize error page

This article mainly introduces the method of customizing error pages and prompt pages in ThinkPHP. It describes in detail the method of implementing customized error prompts and jump pages in ThinkPHP in the form of a complete example. It is a very common practical skill. Friends in need can refer to

. This article describes how to customize error pages and prompt pages in ThinkPHP. Share it with everyone for your reference. The specific implementation method is as follows:

When there are two methods in ThinkPHP, the error page is prompted_404('error message','jump address');halt('prompt message');
This Both functions can customize the error page by adding

to the configuration file. Copy the code . The code is as follows:

'TMPL_EXCEPTION_FILE'=>'./Public/Tpl/error.html'
Copy after login

This will jump to this page every time.

The following is my customized error page

Copy code The code is as follows:

Automatically jump after (3) seconds, or Click here to jump to stop

$this->success('错误信息','跳转的地址(最好用U())',时间);
$this->error();
Copy after login

The following is the prompt page I changed in ThinkPHP

Copy code The code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<title>提示消息 - ThinkPHP</title>   
  
<style type="text/css">   
body { font: 75% Arail; text-align: center; }   
#notice { width: 300px; background: #FFF; border: 1px solid #BBB; background: #EEE; padding: 3px;   
position: absolute; left: 50%; top: 50%; margin-left: -155px; margin-top: -100px; }   
#notice p { background: #FFF; padding: 30px 0 20px; font-size: 1.2em; font-weight:bold }   
#notice p { background: #FFF; margin: 0; padding: 0 0 20px; }   
a { color: #f00} a:hover { text-decoration: none; }   
</style>   
</head>   
<body>   
<p id="notice">   
  
<present name="message">   
<p style="font: italic bold 2cm cursive,serif; color:green">   
ok    
</p>   
<p class="success" style="width:100%;text-align:left;padding-left:10px;padding-right:10px">   
<?php echo($message); ?>   
</p>   
<else/>   
<p style="font: italic bold 2cm cursive,serif; color:red">   
×   
</p>   
<p class="error" style="width:100%;text-align:left;padding-left:10px;padding-right:10px">   
</p>   
</present> 
<p>   
在( <span id="sec" style="color:blue;font-weight:bold"><?php echo($waitSecond); ?></span> )秒后自动跳转,或直接点击 <a href="javascript:window.location=&#39;<?php echo($jumpUrl); ?>&#39;">这里</a> 跳转<br>   
<span style="display:block;text-decoration:underline;cursor:pointer;line-height:25px" onclick="stop(this)">停止</span>   
</p>   
</p>   
<script>   
var seco=document.getElementByIdx_x("sec");   
var time=<?php echo($waitSecond); ?>;   
var tt=setInterval(function(){   
time--;   
seco.innerHTML=time;   
if(time<=0){   
window.location=&#39;<?php echo($jumpUrl); ?>&#39;  
return;   
}   
}, 1000);   
function stop(obj){   
clearInterval(tt);   
obj.style.display="none";   
}   
</script>   
</body>   
</html>
Copy after login

Related Recommended:

How to set up a custom directory structure in ThinkPHP

##

The above is the detailed content of Custom error pages and prompt pages in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to quickly set up a custom avatar in Netflix How to quickly set up a custom avatar in Netflix Feb 19, 2024 pm 06:33 PM

An avatar on Netflix is ​​a visual representation of your streaming identity. Users can go beyond the default avatar to express their personality. Continue reading this article to learn how to set a custom profile picture in the Netflix app. How to quickly set a custom avatar in Netflix In Netflix, there is no built-in feature to set a profile picture. However, you can do this by installing the Netflix extension on your browser. First, install a custom profile picture for the Netflix extension on your browser. You can buy it in the Chrome store. After installing the extension, open Netflix on your browser and log into your account. Navigate to your profile in the upper right corner and click

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to customize shortcut key settings in Eclipse How to customize shortcut key settings in Eclipse Jan 28, 2024 am 10:01 AM

How to customize shortcut key settings in Eclipse? As a developer, mastering shortcut keys is one of the keys to improving efficiency when coding in Eclipse. As a powerful integrated development environment, Eclipse not only provides many default shortcut keys, but also allows users to customize them according to their own preferences. This article will introduce how to customize shortcut key settings in Eclipse and give specific code examples. Open Eclipse First, open Eclipse and enter

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

The operation process of edius custom screen layout The operation process of edius custom screen layout Mar 27, 2024 pm 06:50 PM

1. The picture below is the default screen layout of edius. The default EDIUS window layout is a horizontal layout. Therefore, in a single-monitor environment, many windows overlap and the preview window is in single-window mode. 2. You can enable [Dual Window Mode] through the [View] menu bar to make the preview window display the playback window and recording window at the same time. 3. You can restore the default screen layout through [View menu bar>Window Layout>General]. In addition, you can also customize the layout that suits you and save it as a commonly used screen layout: drag the window to a layout that suits you, then click [View > Window Layout > Save Current Layout > New], and in the pop-up [Save Current Layout] Layout] enter the layout name in the small window and click OK

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

See all articles