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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 3.5 smarty模板引擎 ### 1. 安裝 smarty/smarty 模板引擎 ~~~ composer require smarty/smarty ~~~ 官網:<http://www.smarty.net/docs/zh_CN/> ### 2. 使用模板引擎 *D:\wamp\www\web.com\core\thinkphp.php* 初始化時,實例化模板引擎類 ~~~ public function __construct() { // 模板引擎實例化、設置 $this->smarty = new \Smarty; $this->smarty->setTemplateDir(APP.'/view/'); $this->smarty->setCompileDir(THINKPHP.'/log/view_c'); $this->smarty->setCacheDir(THINKPHP.'/log/cache/'); // $smarty->force_compile = true; // $this->smarty->debugging = true; // $this->smarty->caching = true; $this->smarty->cache_lifetime = 120; } ~~~ 定義的2個方法 ~~~ // 傳遞數據 public function assign($name, $value) { $this->smarty->assign($name, $value); } // 顯示視圖 public function display($file) { $this->smarty->display($file); } ~~~ ### 3. 控制器調用模型 *D:\wamp\www\web.com\app\ctrl\indexCtrl.php* ~~~ <?php namespace app\ctrl; use app\model\catModel; class indexCtrl extends \core\thinkphp { public function index() { // 實例化模型 $model = new catModel(); $ret = $model->lists(); $this->assign("cats", $ret); // 傳遞數據 $this->display('index/index.html'); // 顯示視圖 } } ~~~ 從數據庫獲取的數組信息,保存在變量中。 ### 4. 創建模板文件 *D:\wamp\www\web.com\app\view\index\index.html* ~~~ {$cats|dump} ~~~ ![](https://box.kancloud.cn/1487fbe226a5dd1e11b4fa7f3a058859_759x552.png) 模板引擎最大的特點是模板繼承等特性。 我們創建一個模板文件:*D:\wamp\www\web.com\app\view\layouts\main.html* ~~~ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>視圖文件</title> </head> <body> <header> 頭部區域 </header> <div class="content"> <p>內容區域</p> {block name=body}{/block} </div> <footer> 尾部區域 </footer> </body> </html> ~~~ 在視圖文件中使用 `foreach` 進行循環遍歷顯示數據 *D:\wamp\www\web.com\app\view\index\index.html* ~~~ {extends file='layouts/main.html'} {block name=body} <table border="1" width="50%"> {foreach $cats as $i} <tr> <td>{$i['cat_id']}</td> <td>{$i.catname}</td> <td>{$i.num}</td> </tr> {/foreach} </table> {/block} ~~~ ![](https://box.kancloud.cn/39352176e0c69a3707c87aded0c57e31_759x552.png)
                  <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>

                              哎呀哎呀视频在线观看