<?php
<liu21st@gmail.com>
namespace think\response;
use think\Config;
use think\Response;
use think\View as ViewTemplate;
class View extends Response
{
protected $options = [];
protected $vars = [];
protected $replace = [];
protected $contentType = 'text/html';
protected function output($data)
{
return ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))
->fetch($data, $this->vars, $this->replace);
}
public function getVars($name = null)
{
if (is_null($name)) {
return $this->vars;
} else {
return isset($this->vars[$name]) ? $this->vars[$name] : null;
}
}
public function assign($name, $value = '')
{
if (is_array($name)) {
$this->vars = array_merge($this->vars, $name);
return $this;
} else {
$this->vars[$name] = $value;
}
return $this;
}
public function replace($content, $replace = '')
{
if (is_array($content)) {
$this->replace = array_merge($this->replace, $content);
} else {
$this->replace[$content] = $replace;
}
return $this;
}
}