<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國際加速解決方案。 廣告
                **1 小試身手** * * * * * 1 建立模板文件 打開目錄D:\upnp5.6\htdocs\tp5\application\index,建立view目錄。 進入模塊的模板目錄D:\upnp5.6\htdocs\tp5\application\index\view\ 建立模板文件test_fetch.html,輸入以下內容 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Thinkphp模板測試文件</title> </head> <body> 這里是Viewtest:test_fetch的模板文件 </body> </html> ~~~ 建立模板文件test_assign.html,輸入以下內容 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Thinkphp模板測試文件</title> </head> <body> 這里是Viewtest:test_assign的模板文件.<br> 名稱信息:{$name};<br> 郵件信息:{$email};<br> </body> </html> ~~~ * * * * * 2 建立渲染測試控制器文件 打開控制器目錄D:\upnp5.6\htdocs\tp5\application\index\controller\ 建立模板測試文件Viewtest.php,輸入以下內容。 ~~~ <?php namespace app\index\controller; use think\View; class Viewtest { public function test_fetch(){ $view = new View(); return $view->fetch(); } public function test_assign(){ $view = new View(); $view->assign('name','Thinkphp'); $view->assign('email','Test@ee.com'); return $view->fetch(); } } ~~~ * * * * * 3 瀏覽器測試 輸入http://127.0.0.1/tp5/public/index.php/Index/Viewtest/test_fetch 輸出如下 ![](https://box.kancloud.cn/2016-02-25_56ce6e41524e7.jpg) 輸入http://127.0.0.1/tp5/public/index.php/Index/Viewtest/test_assign 輸出如下 ![](https://box.kancloud.cn/2016-02-25_56ce6e48e6601.jpg) 4 總結 框架的渲染由think/View類封裝。 可以單獨創建think/View對象,然后調用assign,fetch等方法。 也可以直接繼承think/Controller類,調用controller封裝的assign,fetch方法。 **2 開發場景** 這里是后端與前端的主要配合工作,根據公司流程安排分配合作。 **3 開發進階** * * * * * 1 修改視圖渲染配置, 修改$view的view_suffix可以修改模板后綴, 修改$view的view_depr可以修改模板分層。 打開控制器目錄D:\upnp5.6\htdocs\tp5\application\index\controller\ 新建Viewconfig.php文件,輸入以下內容 ~~~ <?php namespace app\index\controller; use think\View; class Viewconfig { public function test_fetch(){ $view = new \think\View(['view_suffix'=>'.htm','view_depr'=>'_']); return $view->fetch(); } public function test_assign(){ $view = new View(); $view->config(['view_suffix'=>'.htm','view_depr'=>'_']); $view->assign('name','Thinkphp'); $view->assign('email','Test@ee.com'); return $view->fetch(); } } ~~~ 瀏覽器輸入 http://127.0.0.1/tp5/public/index.php/Index/Viewconfig/test_fetch 輸出如下 ![](https://box.kancloud.cn/2016-02-25_56ce6e490583c.jpg) 可知模板文件的路徑為application\index\view\viewconfig_test_fetch.htm 進入application\index\view\ 分別建立對應模板文件,文件名格式為:**小寫控制器名稱_小寫方法名稱.后綴**, viewconfig_test_fetch.htm,輸入以下內容 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Thinkphp模板測試文件</title> </head> <body> 這里是Viewconfig:test_fetch的模板文件 </body> </html> ~~~ viewconfig_test_assign.htm,輸入以下內容 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Thinkphp模板測試文件</title> </head> <body> 這里是Viewconfig:test_assign的模板文件.<br> 名稱信息:{$name};<br> 郵件信息:{$email};<br> </body> </html> ~~~ 瀏覽器輸入 http://127.0.0.1/tp5/public/index.php/Index/Viewconfig/test_fetch http://127.0.0.1/tp5/public/index.php/Index/Viewconfig/test_assign 正常輸出模板。 view的相關配置參數見thinkphp\library\think\View.php文件。 ~~~ protected $config = [ 'theme_on' => false, 'auto_detect_theme' => false, 'var_theme' => 't', 'default_theme' => 'default', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS, 'view_layer' => VIEW_LAYER, 'parse_str' => [], 'engine_type' => 'think', 'namespace' => '\\think\\view\\driver\\', ]; ~~~ * * * * * 2 自定義渲染引擎 tp5默認使用Think渲染引擎, 實現在\thinkphp\library\think\view\driver\Think.php文件。 ~~~ namespace think\view\driver; use think\Template; class Think { private $template = null; public function __construct($config = []) { $this->template = new Template($config); } public function fetch($template, $data = [], $cache = []) { if (is_file($template)) { $this->template->display($template, $data, $cache); } else { $this->template->fetch($template, $data); } } } ~~~ 分析可知需要實現fetch()方法。 可以參考tp3.2的\ThinkPHP\Library\Think\Template\Driver\目錄下的 Smarty.class.php文件,添加Smarty渲染引擎的支持。 更多的模板引擎參考[官方手冊](http://www.hmoore.net/manual/thinkphp/1785) * * * * * 3 自定義模板標簽 視圖渲染的模板標簽配置在thinkphp\library\think\Template.php文件中定義 ~~~ protected $config = [ 'view_path' => '', 'view_suffix' => '.html', 'cache_suffix' => '.php', 'tpl_deny_func_list' => 'echo,exit', 'tpl_deny_php' => false, 'tpl_begin' => '{', 'tpl_end' => '}', 'strip_space' => false, 'tpl_cache' => true, 'compile_type' => 'file', 'cache_prefix' => '', 'cache_time' => 0, 'cache_record_file' => 'cache_record_file', 'layout_on' => false, 'layout_name' => 'layout', 'layout_item' => '{__CONTENT__}', 'taglib_begin' => '{', 'taglib_end' => '}', 'taglib_load' => true, 'taglib_build_in' => 'cx', 'taglib_pre_load' => '', 'display_cache' => false, 'cache_id' => '', 'tpl_replace_string' => [], 'tpl_var_identify' => 'array', 'namespace' => '\\think\\template\\driver\\', ]; ~~~ 可以通過修改convention.php的模板配置參數 `'template_engine' => 'Think',` 或者$view->engine()方法修改模板標簽參數 **4 框架底層** 模板的視圖渲染是業務邏輯的內容輸出控制。 在控制器中,處理業務邏輯數據模型后,將輸出結果以模板文件的方式顯示。 視圖渲染將帶有think框架標簽的模板文件編譯為普通的php標簽模板文件, 然后由php運行環境解析執行后輸出到客戶端。 tp5繼承thinkphp3.2內置的豐富標簽庫與渲染引擎。 模板標簽的使用見[官方手冊 ](http://www.hmoore.net/manual/thinkphp/1793)。
                  <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>

                              哎呀哎呀视频在线观看