ThinkPHP架構 祖輩分的理解 【兒子 FenyeController】繼承了【父親 FuController】繼承了【祖輩 Controller】的

來源:互聯網
上載者:User

標籤:顯示   構造   訪問   log   cti   第一個   存在   array   時間   

注:系統內建的Controller方法代表的是祖輩    FuController控制器是自訂的,代表父親。。。        FenyeController控制器就代表著兒子     

【兒子 FenyeController】繼承了【父親 FuController】繼承了【祖輩 Controller】的


在模組控制器Controller檔案夾裡建立一個簡單的 LoginController.class.php控制器
<?phpnamespace Admin\Controller;use Think\Controller;class LoginController extends Controller{        public function login(){                session(‘uid‘,‘zhangsan‘);//存一個session值    }    }

在模組控制器Controller檔案夾裡建立一個簡單的 FuController.class.php控制器
 
<?phpnamespace Admin\Controller;use Think\Controller;class FuController extends Controller{//造一個FuController控制器,用來判斷session值是否存在。        public function __construct(){//造一個建構函式                parent::__construct(); //調用父類構造  不調用此方法再次訪問顯示頁面時會報錯!                if(session("?uid")){//判斷session是否存在,如果存在,什麼也不做。                                }else{//如果不存在就將它直接打回登入頁面去登入                        $this->redirect("Admin/Login/login", array(), 3, ‘請登入....‘);//第一個參數是跳轉的地址,第二個參數是要傳的值,第三個參數是跳轉的時間,第四個參數是跳轉時的提示資訊。            exit;        }    }}

 

 

<?phpnamespace Admin\Controller;use Admin\Controller\FuController;class FenyeController extends FuController{//這裡繼承的父類更改為FuController        public function xianshi(){        $c = D("chinastates");        $shuliang = $c->count();//求出總數量        $page = new \Admin\page\Page($shuliang,15);//分頁類對象        //var_dump($page);        $xinxi = $page->fpage();//調出fpage()分頁資訊                $attr = $c->limit($page->limit)->select();//調出分頁裡的limit()方法,                $this->assign("shuju",$attr);        $this->assign("xinxi",$xinxi);        $this->show();                    }}

 

ThinkPHP架構 祖輩分的理解 【兒子 FenyeController】繼承了【父親 FuController】繼承了【祖輩 Controller】的

聯繫我們

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