<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國際加速解決方案。 廣告
                > ## 依賴注入請求對象(針對控制器) ### 如果繼承了系統的Controller類的話,可以直接調用request屬性,例如: ``` use think\Controller; class Index extends Controller { public function hello() { return 'Hello,'.$this->request->param('name'); } } ``` ### 注入控制器的構造方法中 ``` use think\Request; class Index { protected $request; // 用來保存請求對象 // 將請求對象注入構造方法 public function __construct(Request $request) { $this->request = $request; } // 在其他方法中使用請求對象 public function hello() { return 'Hello,' . $this->request->param('name') . '!'; } } ``` ### 注入控制器的一般方法中 ``` use think\Request; class Index { public function hello(Request $request) { return 'Hello,' . $request->param('name') . '!'; } } ``` >## 依賴注入任意類的對象(針對控制器) ### 注入控制器的構造方法中 ``` use app\index\model\User; class Index { protected $user; public function __construct(User $user) { $this->user = $user; } } ``` ### 注入控制器的一般方法中 ``` use app\index\model\User; use think\Controller; class Index extends Controller { public function hello(User $user) { return 'Hello,'.$user->name; } } // 事先在Request進行對象綁定 Request::instance()->bind('user', \app\index\model\User::get(1)); // 如果沒有事先在Request進行對象綁定,那么當調用hello方法時會自動實例化一個對象,相當于下面 Request::instance()->bind('user', new \app\index\model\User); ``` ### 調用依賴注入類的靜態invoke方法可以自動實例化注入的對象 ``` class User extends Model { // 需要傳入當前請求對象作為參數 public static function invoke(Request $request) { $id = $request->param('id'); return User::get($id); } } ```
                  <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>

                              哎呀哎呀视频在线观看