Heim  >  Artikel  >  php教程  >  thinkphp框架下404页面设置 仅三步,thinkphp404

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

WBOY
WBOYOriginal
2016-06-13 08:39:221450Durchsuche

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

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

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

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

<&#63;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");
  }
}
&#63;>

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

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

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

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

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

<&#63;php
namespace HomeController;
// use ThinkController;
class IndexController extends PublicController {
  public function index(){
  
    *
    *
    *
     }
}
?>

注意:将use ThinkController;注释掉

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn