for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// | Author: liu21st <[email protected]>
namespace think\response;
use think\Response;
class View extends Response
{
// 输出参数
protected $options = [];
protected $vars = [];
protected $filter;
protected $contentType = 'text/html';
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return string
*/
protected function output($data): string
// 渲染模板输出
return \think\facade\View::filter($this->filter)
->assign($this->vars)
->fetch($data);
}
* 获取视图变量
* @access public
* @param string $name 模板变量
* @return mixed
public function getVars(string $name = null)
if (is_null($name)) {
return $this->vars;
} else {
return $this->vars[$name] ?? null;
* 模板变量赋值
* @param array $vars 变量
* @return $this
public function assign(array $vars)
$this->vars = array_merge($this->vars, $vars);
return $this;
* 视图内容过滤
* @param callable $filter
public function filter(callable $filter = null)
$this->filter = $filter;
* 检查模板是否存在
* @param string $name 模板名
* @return bool
public function exists(string $name): bool
return \think\facade\View::exists($name);
return think\facade\View::exists($name)
think\View
boolean