当前位置:Gxlcms > PHP教程 > thinkphp框架下404页面设置thinkphp支持php5.2thinkphp文件thinkphptags.ph

thinkphp框架下404页面设置thinkphp支持php5.2thinkphp文件thinkphptags.ph

时间:2021-07-01 10:21:17 帮助过:16人阅读

404页面即系统在找不到请求的操作方法和找不到请求的控制器名称时的一种报错行为的优化。

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

namespace Home\Controller;
use Think\Controller;
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 Home\Controller;
use Think\Controller;
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 Home\Controller;
// use Think\Controller;class IndexController extends PublicController {
    publicfunction index(){
    
        *
        *
        *         }
}
?>

注意:将use Think\Controller;注释掉

(完成)

以上就介绍了thinkphp框架下404页面设置,包括了thinkphp,PHP框架方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行