您的位置:首页 > 编程语言 > PHP开发

thinkphp框架下404页面设置 仅三步

2016-05-14 00:00 791 查看
404页面即系统在找不到请求的操作方法和找不到请求的控制器名称时的一种报错行为的优化。

在很多网站中都会有使用404页面的时候,在ThinkPHP框架中该如何设置呢,接下来我介绍其中一种方法,具体内容如下

第一步:在thinkphp框架中的Home/Comtroller中建一个EmptyController.class.php,其代码如下:

<?php
namespace HomeController;
use ThinkController;
class EmptyController extends Controller{

  //空操作_empty()方法
function _empty(){
header("HTTP/1.0 404 Not Found");
$this -> display("Public:404");
}

function index(){
header("HTTP/1.0 404 Not Found");
$this -> dislay("Public:404");
}
}
?>


注意:其中 header("HTTP/1.0 404 Not Found")是定义此状态码未404。

第二步:在thinkphp框架中的Home/Comtroller中建一个公共的类PublicController.class.php,其代码如下:

<?php
namespace HomeController;
use ThinkController;
class PublicController extends Controller{
function _empty(){
header("Location:/bbs/thinkphp/404.html");
}
}
?>


注意:其中 header("Location:/bbs/thinkphp/404.html")中的/bbs/thinkphp/404.html是你出现404后页面跳转的地址,需和自己的404.html页面放置位对应。

第三步:让其他控制器全部继承 第二步中的PublicController.class.php,比如:

<?php
namespace HomeController;
// use ThinkController;
class IndexController extends PublicController {
public function index(){

*
*
*
}
}
?>


注意:将use ThinkController;注释掉

以上就是thinkphp 404页面设置的全部内容,希望对大家学习php程序设计有所帮助。

您可能感兴趣的文章:

php 404错误页面实现代码
php 智能404跳转代码,适合换域名没改变目录的网站
php 定义404页面的实现代码
用php来改写404错误页让你的页面更友好
PHP header()函数使用详细(301、404等错误设置)
ThinkPHP访问不存在的模块跳转到404页面的方法
PHP统计nginx访问日志中的搜索引擎抓取404链接页面路径
ThinkPHP 404页面的设置方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  thinkphp 404