<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Understanding How Phalcon Applications Work 如果你已經看過了[tutorial](http://docs.iphalcon.cn/reference/tutorial.html)或者已經通過[Phalcon Devtools](http://docs.iphalcon.cn/reference/tools.html)生成了代碼, 你將很容易識別以下的啟動文件: ~~~ <?php use Phalcon\Mvc\Application; // 注冊自動加載器 // ... // 注冊服務 // ... // 處理請求 $application = new Application($di); try { $response = $application->handle(); $response->send(); } catch (\Exception $e) { echo "Exception: ", $e->getMessage(); } ~~~ 控制器中全部核心的工作都會在handle()被回調時觸發執行。 ~~~ <?php $response = $application->handle(); ~~~ ## 手動啟動(Manual bootstrapping) 如果你不想使用[Phalcon\\Mvc\\Application](http://docs.iphalcon.cn/api/Phalcon_Mvc_Application.html),以上的代碼可以改成這樣: ~~~ <?php // 獲取 'router' 服務 $router = $di["router"]; $router->handle(); $view = $di["view"]; $dispatcher = $di["dispatcher"]; // 傳遞路由的相關數據傳遞給調度器 $dispatcher->setControllerName( $router->getControllerName() ); $dispatcher->setActionName( $router->getActionName() ); $dispatcher->setParams( $router->getParams() ); // 啟動視圖 $view->start(); // 請求調度 $dispatcher->dispatch(); // 渲染相關視圖 $view->render( $dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams() ); // 完成視圖 $view->finish(); $response = $di["response"]; // 傳遞視圖內容給響應對象 $response->setContent( $view->getContent() ); // Send the response $response->send(); ~~~ 以下代碼替換了[Phalcon\\Mvc\\Application](http://docs.iphalcon.cn/api/Phalcon_Mvc_Application.html),雖然缺少了視圖組件, 但卻更適合Rest風格的API接口: ~~~ <?php use Phalcon\Http\ResponseInterface; // 獲取 'router' 服務 $router = $di["router"]; $router->handle(); $dispatcher = $di["dispatcher"]; // 傳遞路由的相關數據傳遞給調度器 $dispatcher->setControllerName( $router->getControllerName() ); $dispatcher->setActionName( $router->getActionName() ); $dispatcher->setParams( $router->getParams() ); // 請求調度 $dispatcher->dispatch(); // 獲取最后的返回結果 $response = $dispatcher->getReturnedValue(); // 判斷結果是否是 'response' 對象 if ($response instanceof ResponseInterface) { // 發送響應 $response->send(); } ~~~ 另外一個修改就是在分發器中對拋出異常的捕捉可以將請求轉發到其他的操作: ~~~ <?php use Phalcon\Http\ResponseInterface; // 獲取 'router' 服務 $router = $di["router"]; $router->handle(); $dispatcher = $di["dispatcher"]; // 傳遞路由的相關數據傳遞給調度器 $dispatcher->setControllerName( $router->getControllerName() ); $dispatcher->setActionName( $router->getActionName() ); $dispatcher->setParams( $router->getParams() ); try { // 請求調度 $dispatcher->dispatch(); } catch (Exception $e) { // An exception has occurred, dispatch some controller/action aimed for that // Pass the processed router parameters to the dispatcher $dispatcher->setControllerName("errors"); $dispatcher->setActionName("action503"); // Dispatch the request $dispatcher->dispatch(); } // 獲取最后的返回結果 $response = $dispatcher->getReturnedValue(); // 判斷結果是否是 'response' 對象 if ($response instanceof ResponseInterface) { // 發送響應 $response->send(); } ~~~ 盡管上面的代碼比使用[Phalcon\\Mvc\\Application](http://docs.iphalcon.cn/api/Phalcon_Mvc_Application.html)而需要的代碼遠遠要累贅得很, 但它為啟動你的應用提供了一個可修改、可定制化的途徑。 因為根據你的項目需要,你可以想對實例什么和不實例化什么進行完全的控制,或者想用你自己的組件來替代那些確定和必須的組件從而擴展默認的功能。
                  <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>

                              哎呀哎呀视频在线观看