thinkphp架構下404版面設定,thinkphp404_PHP教程

來源:互聯網
上載者:User

thinkphp架構下404版面設定,thinkphp404


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,其代碼如下:

phpnamespace 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,比如:

phpnamespace Home\Controller;// use Think\Controller;class IndexController extends PublicController {    public function index(){            *        *        *         }}?>

注意:將use Think\Controller;注釋掉

(完成)

http://www.bkjia.com/PHPjc/1125677.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1125677.htmlTechArticlethinkphp架構下404版面設定,thinkphp404 404頁面即 系統在找不到請求的操作方法和找不到請求的控制器名稱 時的一種報錯行為的最佳化。 第一步...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.