<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                QueryPHP 控制器定義設計得非常靈活,可以有多種情況,下面一個個為大家講解一下。 # 1):繼承至 Q\mvc\controller home 應用編寫一個 hello 控制器,控制器的路徑為 **<project>/app/home/controller/hello.php** ~~~ <?php namespace home\controller; use Q\mvc\controller; class hello extends controller { /** * 默認方法 */ public function index() { $this->assign('strSay', 'hello world'); $this->display(); } } ~~~ 定義模板文件,實際路徑為 **<project>/app/home/theme/default/hello_index.html** ~~~ 我想對世界說 {$strSay} ~~~ 訪問該控制器 url 地址: ~~~ http://<service>/?c=hello ~~~ 輸出結果: ~~~ 我想對世界說 hello world ~~~ # 2):不繼承任何控制器 為實現上面相同的功能,我們這里不繼承任何控制器,手動去調用視圖,輸出結果見上面。 ~~~ <?php namespace home\controller; use Q\mvc\view; class hello { /** * 默認方法 */ public function index() { $objView = view::run (); $objView->assign ( 'strSay', 'hello world' ); $objView->display (); } } ~~~ # 3):注冊控制器為回調 控制器可以為一個回調,這種情況需要預先注冊,新建一個路由配置文件,位置為 **<project>/app/home/option/router.php**。 ### 1:匿名函數支持 ~~~ <?php // 匿名函數回調 router::bind ( 'hello', function( ){ $this->assign ( 'strSay', '匿名函數' ); $this->display (); } ); ~~~ 輸出結果: ~~~ 我想對世界說 匿名函數 ~~~ ### 2:靜態類回調支持 修改路由文件 router.php,改為如下: ~~~ <?php class helloworld { /** * 返回 say * * @return string */ public static function getSay($that) { $that->assign ( 'strSay', '靜態回調' ); $that->display (); } } // 注冊路由 router::bind ( 'hello', [ 'helloworld', 'getSay' ] ); ~~~ 輸出結果: ~~~ 我想對世界說 靜態回調 ~~~ ### 3:對象實例回調支持 修改路由文件 router.php,改為如下: ~~~ <?php class helloworld { /** * 返回 say * * @return string */ public function getSay($that) { $that->assign ( 'strSay', '實例回調' ); $that->display (); } } // 注冊路由 router::bind ( 'hello', [ new helloworld (), 'getSay' ] ); ~~~ 輸出結果: ~~~ 我想對世界說 實例回調 ~~~ # 4):注冊繼承至 Q\mvc\action 修改路由文件 router.php,改為如下: ~~~ <?php use Q\mvc\action; class helloworld extends action{ /** * 返回 say * * @return string */ public function run($that, $in = []) { $that->assign ( 'strSay', '繼承至 Q\base\action' ); $that->display (); } } // 注冊路由 router::bind ( 'hello', new helloworld() ); ~~~ 輸出結果: ~~~ 我想對世界說 繼承至 Q\mvc\action ~~~ # 5):注冊繼承至 Q\mvc\controller 修改路由文件 router.php,改為如下: ~~~ <?php use Q\mvc\controller; class helloworld extends controller{ /** * 返回 say * * @return string */ public function index() { $this->assign ( 'strSay', '繼承至 Q\base\controller' ); $this->display (); } } // 注冊路由 router::bind ( 'hello', new helloworld() ); ~~~ 輸出結果: ~~~ 我想對世界說 繼承至 Q\mvc\controller ~~~ # 6):注冊對象實例 修改路由文件 router.php,改為如下: ~~~ <?php class helloworld{ /** * 返回 say * * @return string */ public function index($that, $in) { $that->assign ( 'strSay', '注冊對象實例' ); $that->display (); } } // 注冊路由 router::bind ( 'hello', new helloworld() ); ~~~ 輸出結果: ~~~ 我想對世界說 注冊對象實例 ~~~ # 7):注冊普通數據類型 普通數據類型將會被直接輸出,修改路由文件 router.php,改為如下: ~~~ <?php // 基本數據類型 string,integer,float,boolean,numeric,null $booHello = true; // 注冊路由 router::bind ( 'hello', $booHello ); ~~~ 輸出結果: ~~~ 1 ~~~ # 8):注冊數組類型 如果控制器為數組,那么鍵值則為方法,修改路由文件 router.php,改為如下: ### 1:回調支持 回調包括上面的匿名函數、靜態回調和對象實例回調,這里只測試一種。 ~~~ <?php $calHello = function( ){ $this->assign ( 'strSay', '數組匿名函數' ); $this->display (); }; // 注冊路由 router::bind ( 'hello', ['index' => $calHello]); ~~~ 輸出結果: ~~~ 我想對世界說 匿名函數 ~~~ ### 2:數組支持 如果為數組直接返回 json,這里只測試一種。 ~~~ <?php $arrHello = ['name' => '我的世界', 'description' => '我樂我生活,你享你世界']; // 注冊路由 router::bind ( 'hello', ['index' => $arrHello]); ~~~ 輸出結果: ~~~ {"name":"我的世界","description":"我樂我生活,你享你世界"} ~~~ ### 3:其它類型支持 數組的值可以還支持普通數據類型,**Q\base\action** 等,重復上面的注冊支持類型,只是值如果為數組則輸出 json。 ~~~ <?php $strHello = 'Ye,good'; // 注冊路由 router::bind ( 'hello', ['index' => $strHello]); ~~~ 輸出結果: ~~~ Ye,good ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看