空操做和空模塊頗有實用意義,他有些相似於PHP虛擬機自定義的404頁面,利用這個機制咱們能夠更好的實現URL和錯誤頁面的一些優化。php
一.空模塊:thinkphp
很好理解,就是當你執行不存在模塊的時候,thinkphp會自動尋找該模塊,當找不到該模塊的時候,Thinkphp會自動定義空模塊下的index方法。優化
<?php class EmptyController extends Controller{ public function index(){ echo '<script>window.location.href="../Er/error"</script>'; }
這是一個簡單的空模塊,能夠根據項目需求進行開發spa
二.空操做:code
空操做就是,當你在當前模塊,執行這個模塊沒有的方法時,會自動跳轉到_empty這個方法,而且能夠和空模塊同時使用。blog
例如,index模塊下定義一個空操做ip
<?php class IndexController extendx Controller{ public function index(){ echo "index function"; } public function _empty(){ echo '<script>window.location.href="../Er/error"</script>'; }
到這就OK了! 更加複雜的就要具體事情具體分析了!!開發