thinkphp3.2.2前後台公用類架構問題,thinkphp3.2.2公用_PHP教程

來源:互聯網
上載者:User

thinkphp3.2.2前後台公用類架構問題,thinkphp3.2.2公用


3.13之前好多項目都使用前後台公用類,在lib/action下建立Baseaction做為公用繼承類,發現3.2.2裡面很多人都用A調用,這樣每用一次要用A調用,好麻煩,小編特意偷懶。親測使用以下方法解決。歡迎加強

thinkphp3.2.2的這麼建立Application/Common/Controller/BaseController.class.php

 1 php 2 namespace Common\Controller; 3 use Think\Controller; 4     /** 5     * 前後台公用基類 6     * modify author : Jack 7     * modify time : 2014-7-12 8     */ 9     class BaseController extends Controller{10         11         public function _initialize() {//全域變數12                dump('基類');13             $this->cfg();14         }15      }

在Home/Controller/ZixunController.class.php中

phpnamespace Home\Controller;use Common\Controller\BaseController;class ZixunController extends BaseController {    public function index() {        $result = $this->lists();        dump($result);    }}

當然,在前後台還可以建立自己的基類,比如後台建AdminController.class.php繼承BaseController.class.php,前台建立HomeController.class.php繼承BaseController.class.php各自模組繼承各自的基類,這樣項目可以更清晰,可以避免重複造輪子,省很多事情,但是必須注意的是每個類必須聲明命名空間,但是使用的資源可以在各自的基類中定義之後後面不用在寫一次。比如AdminController.class.php繼承BaseController.class.php,就不用再寫use Think\Controller了,直接使用use Common\Controller\BaseController就可以了。

http://www.bkjia.com/PHPjc/916820.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/916820.htmlTechArticlethinkphp3.2.2前後台公用類架構問題,thinkphp3.2.2公用 3.13之前好多項目都使用前後台公用類,在lib/action下建立Baseaction做為公用繼承類,發現...

  • 聯繫我們

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