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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 請求對象 當前的請求對象由`think\Request`類負責,在很多場合下并不需要實例化調用,通常使用依賴注入即可。在其它場合(例如模板輸出等)則可以使用`think\facade\Request`靜態類操作。 - [請求對象調用](#_5) - [構造方法注入](#_9) - [操作方法注入](#_60) - [Facade調用](#Facade_84) - [助手函數](#_107) ## 請求對象調用 在控制器中通常情況下有兩種方式進行依賴注入。 ### 構造方法注入 ``` <?php namespace app\index\controller; use think\Request; class Index { /** * @var \think\Request Request實例 */ protected $request; /** * 構造方法 * @param Request $request Request對象 * @access public */ public function __construct(Request $request) { $this->request = $request; } public function index() { return $this->request->param('name'); } } ``` > 如果你繼承了系統的控制器基類`think\Controller`的話,系統已經自動完成了請求對象的構造方法注入了,你可以直接使用`$this->request`屬性調用當前的請求對象。 ``` <?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function index() { return $this->request->param('name'); } } ``` ### 操作方法注入 另外一種選擇是在每個方法中使用依賴注入。 ``` <?php namespace app\index\controller; use think\Controller; use think\Request; class Index extends Controller { public function index(Request $request) { return $request->param('name'); } } ``` 無論是否繼承系統的控制器基類,都可以使用操作方法注入。 > 更多關于依賴注入的內容,請參考后續的依賴注入章節。 ## Facade調用 在沒有使用依賴注入的場合,可以通過`Facade`機制來靜態調用請求對象的方法(注意`use`引入的類庫區別)。 ``` <?php namespace app\index\controller; use think\Controller; use think\facade\Request; class Index extends Controller { public function index() { return Request::param('name'); } } ``` 該方法也同樣適用于依賴注入無法使用的場合。 ## 助手函數 為了簡化調用,系統還提供了`request`助手函數,可以在任何需要的時候直接調用當前請求對象。 ``` <?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function index() { return request()->param('name'); } } ```
                  <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>

                              哎呀哎呀视频在线观看