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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                #### 架構函數注入 我們在上一章了解了如何調用當前請求對象實例,現在通過依賴注入把當前的請求對象直接注入到控制器類中,然后使用`$this->request`代替`Request::instance()`來獲取請求對象實例。 下面先看一段代碼示例: ~~~ <?php namespace app\index\controller; use think\Request; class Index { protected $request; public function __construct(Request $request) { $this->request = $request; } public function hello() { return 'Hello,' . $this->request->param('name') . '!'; } } ~~~ 當我們訪問 ~~~ http://tp5.com/index/index/hello/name/thinkphp ~~~ 頁面輸出結果顯示: ~~~ Hello,thinkphp! ~~~ > 事實上,如果繼承內置的系統控制器基類的話已經可以直接調用request屬性了,在think\Controller類的架構方法里面已經使用了依賴注入,實現的原理是一樣的。 當然,依賴注入不僅僅只是注入Request對象這么簡單,任何一個對象都可以實現注入,而且可以同時注入多個對象示例。 如果當前的控制器類需進行郵件處理(假設我們有一個 `think\Email`類),那么可以在架構函數中進行注入: ~~~ <?php namespace app\index\controller; use think\Email; use think\Request; class Index { protected $request; protected $email; public function __construct(Request $request, Email $email) { $this->request = $request; $this->email = $email; } public function hello() { // 發送Hello郵件 // $this->email->sendMail($this->request->param('address'),'Hello'); return 'Hello,' . $this->request->param('name') . '!'; } } ~~~ `hello方法`中調用`Email類`的`sendMail方法`因為調試問題注釋掉了,僅供參考。 架構函數的參數順序并會不影響依賴注入。
                  <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>

                              哎呀哎呀视频在线观看