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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 視圖賦值 ## 模板賦值 除了系統變量和配置參數輸出無需賦值外,其他變量如果需要在模板中輸出必須首先進行模板賦值操作,否則會拋出異常,傳遞數據到模板輸出有下面幾種方式: ### `assign`方法 在控制器繼承了系統的控制器基類的情況下,可以使用`assign`方法進行模板變量賦值。 ``` namespace index\app\controller; class Index extends \think\Controller { public function index() { // 模板變量賦值 $this->assign('name','ThinkPHP'); $this->assign('email','thinkphp@qq.com'); // 或者批量賦值 $this->assign([ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); // 模板輸出 return $this->fetch('index'); } } ``` ### 方法傳入參數 方法`fetch` 及 `display` 均可傳入模板變量,例如 ``` namespace app\index\controller; class Index extends \think\Controller { public function index() { return $this->fetch('index', [ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); } } ``` ``` class Index extends \think\Controller { public function index() { $content = '{$name}-{$email}'; return $this->display($content, [ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); } } ``` ### 助手函數 如果使用`view`助手函數渲染輸出的話,可以使用下面的方法進行模板變量賦值: ``` return view('index', [ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); ``` 或者 ``` return view('index')->assign([ 'name' => 'ThinkPHP', 'email' => 'thinkphp@qq.com' ]); ``` ### 公共模板變量賦值 如果需要在控制器之外進行模板變量賦值,可以使用視圖類的`share`靜態方法進行全局公共模板變量賦值,例如: ``` use think\facade\View; // 賦值全局模板變量 View::share('name','value'); // 或者批量賦值 View::share(['name1'=>'value','name2'=>'value2']); ``` 全局靜態模板變量最終會和前面使用方法賦值的模板變量合并。
                  <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>

                              哎呀哎呀视频在线观看