Thinkphp空操作空模組

來源:互聯網
上載者:User

標籤:style   錯誤   好的   empty   並且   end   dex   模組   頁面   

空操作和空模組很有實用意義,他有些類似於PHP虛擬機器自訂的404頁面,利用這個機制我們可以更好的實現URL和錯誤頁面的一些最佳化。

一.空模組:

?         很好理解,就是當你執行不存在模組的時候,thinkphp會自動尋找該模組,當找不到該模組的時候,Thinkphp會自動定義空模組下的index方法。

<?php             class EmptyControl?ler extends Controller{                        public function index(){                               echo ‘<script>window.location.href="../Er/error"</script>‘;?                }

?這是一個簡單的空模組,可以根據項目需求進行開發

二.空操作:

      空操作就是,當你在當前模組,執行這個模組沒有的方法時,會自動跳轉到_empty這個方法,並且可以和空模組同時使用。

      例如,index模組下定義一個空操作

<?php           class IndexController extendx Controller{                      public function index(){?                              echo "index function";                      }                      public function _empty(){                              echo ‘<script>window.location.href="../Er/error"</script>‘;?                   }?

到這就OK了! 更加複雜的就要具體事情具體分析了!!

Thinkphp空操作空模組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.