<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 功能強大 支持多語言、二開方便! 廣告
                [TOC] * * * * * # 1 視圖對象 >>視圖(View),作為(MVC)的一員,代表對輸出數據的Web界面組織操作對象。 > 視圖可以用來存儲模板變量 > 最終調用模板引擎 將(模板變量) 與 (模板文件)解析為輸出的Web界面 ### View::instance() >>單例模式,創建全局唯一的視圖對象 ~~~ public static function instance($engine = [], $replace = []) { if (is_null(self::$instance)) { self::$instance = new self($engine, $replace); } return self::$instance; } ~~~ ### $view->__construct() >>視圖構造函數,創建視圖對象 ~~~ public function __construct($engine = [], $replace = []) { // 初始化模板引擎 $this->engine((array) $engine); $this->replace = $replace; } ~~~ ### $view->engine() >>模板引擎創建,根據配置創建相應的模板引擎(默認為Think) ~~~ public function engine($options = []) { if (is_string($options)) { $type = $options; $options = []; } else { $type = !empty($options['type']) ? $options['type'] : 'Think'; } $class = false !== strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type); if (isset($options['type'])) { unset($options['type']); } $this->engine = new $class($options); return $this; } ~~~ >>由上可知,默認的模板引擎(Think)實現為view\driver\Think.php文件。模板引擎具體的信息見 模板引擎 章節 ### $view->config() >>模板引擎配置,配置模板引擎參數 ~~~ public function config($name, $value = null) { $this->engine->config($name, $value); return $this; } ~~~ # 2 視圖操作 ## 2-1 模板變量 ### $view->assign() >>存儲數據到模板變量中。 ~~~ public function assign($name, $value = '') { if (is_array($name)) { $this->data = array_merge($this->data, $name); } else { $this->data[$name] = $value; } return $this; } ~~~ ### $view->__get() >> 模板變量獲取快捷操作 ~~~ public function __get($name) { return $this->data[$name]; } ~~~ ### $view->__set() >> 模板變量賦值快捷操作 ~~~ public function __set($name, $value) { $this->data[$name] = $value; } ~~~ ### $view->__isset() >> 模板變量檢測快捷操作 ~~~ public function __isset($name) { return isset($this->data[$name]); } ~~~ ## 2-2 模板文件 >>模板文件,作為界面組織的文件。模板引擎將模板變量填充到模板文件中生成輸出的Web頁面 ### $view->replace() >> 模板字符串替換內容配置 ~~~ public function replace($content, $replace = '') { if (is_array($content)) { $this->replace = array_merge($this->replace, $content); } else { $this->replace[$content] = $replace; } return $this; } ~~~ ### $view->fetch() >> 獲取模板文件解析結果 ~~~ public function fetch($template = '', $vars = [], $replace = [], $config = [], $renderContent = false) { // 模板變量 $vars = array_merge($this->data, $vars); // 頁面緩存 ob_start(); ob_implicit_flush(0); // 渲染輸出 $method = $renderContent ? 'display' : 'fetch'; $this->engine->$method($template, $vars, $config); // 獲取并清空緩存 $content = ob_get_clean(); // 內容過濾標簽 Hook::listen('view_filter', $content); // 允許用戶自定義模板的字符串替換 $replace = array_merge($this->replace, $replace); if (!empty($replace)) { $content = strtr($content, $replace); } return $content; } ~~~ ### $view->display() >> 輸出模板文件解析結果 ~~~ public function display($content, $vars = [], $replace = [], $config = []) { return $this->fetch($content, $vars, $replace, $config, true); } ~~~
                  <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>

                              哎呀哎呀视频在线观看