think\View::fetch PHP Method

fetch() public method

解析和获取模板内容 用于输出
public fetch ( string $template = '', array $vars = [], array $replace = [], array $config = [], boolean $renderContent = false ) : string
$template string 模板文件名或者内容
$vars array 模板输出变量
$replace array 替换内容
$config array 模板参数
$renderContent boolean 是否渲染内容
return string
    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;
    }

Usage Example

Example #1
0
 public function index()
 {
     Slog::log('调试');
     $view = new View();
     return $view->fetch();
 }
All Usage Examples Of think\View::fetch