取消 traits\controller\view类 并入controller类

This commit is contained in:
thinkphp
2016-02-20 11:25:28 +08:00
parent 0521aebd1e
commit 2277add345
3 changed files with 57 additions and 93 deletions

View File

@@ -11,13 +11,14 @@
namespace think;
T('controller/View');
T('controller/Jump');
class Controller
{
use \traits\controller\Jump;
use \traits\controller\View;
// 视图类实例
protected $view = null;
/**
* 前置操作方法列表
@@ -32,12 +33,14 @@ class Controller
*/
public function __construct()
{
$this->view = \think\View::instance(Config::get());
// 控制器初始化
if (method_exists($this, '_initialize')) {
$this->_initialize();
}
// 前置操作方法
// 支持 ['action1','action2'] 或者 ['action1'=>['only'=>'index'],'action2'=>['except'=>'login']]
if ($this->beforeActionList) {
foreach ($this->beforeActionList as $method => $options) {
is_numeric($method) ?
@@ -75,4 +78,53 @@ class Controller
call_user_func([$this, $method]);
}
}
/**
* 加载模板和页面输出 可以返回输出内容
* @access public
* @param string $template 模板文件名
* @param array $vars 模板输出变量
* @param string $cache_id 模板缓存标识
* @return mixed
*/
public function fetch($template = '', $vars = [], $cache_id = '')
{
return $this->view->fetch($template, $vars, $cache_id);
}
/**
* 渲染内容输出
* @access public
* @param string $content 内容
* @param array $vars 模板输出变量
* @return mixed
*/
public function show($content, $vars = [])
{
return $this->view->show($content, $vars);
}
/**
* 模板变量赋值
* @access protected
* @param mixed $name 要显示的模板变量
* @param mixed $value 变量的值
* @return void
*/
public function assign($name, $value = '')
{
$this->view->assign($name, $value);
}
/**
* 初始化模板引擎
* @access protected
* @param string $engine 引擎名称
* @param array $config 引擎参数
* @return void
*/
public function engine($engine, $config = [])
{
$this->view->engine($engine, $config);
}
}

View File

@@ -1,88 +0,0 @@
<?php
/**
* 用法:
* T('controller/View');
* class index
* {
* use \traits\controller\View;
* public function index(){
* $this->assign();
* $this->show();
* }
* }
*/
namespace traits\controller;
use think\Config;
trait View
{
// 视图类实例
protected $view = null;
/**
* 架构函数 初始化视图类 并采用内置模板引擎
* @access public
*/
public function initView()
{
// 模板引擎参数
if (is_null($this->view)) {
$this->view = \think\View::instance(Config::get()); // 只能这样写不然view会冲突
}
}
/**
* 加载模板和页面输出 可以返回输出内容
* @access public
* @param string $template 模板文件名
* @param array $vars 模板输出变量
* @param string $cache_id 模板缓存标识
* @return mixed
*/
public function fetch($template = '', $vars = [], $cache_id = '')
{
$this->initView();
return $this->view->fetch($template, $vars, $cache_id);
}
/**
* 渲染内容输出
* @access public
* @param string $content 内容
* @param array $vars 模板输出变量
* @return mixed
*/
public function show($content, $vars = [])
{
$this->initView();
return $this->view->show($content, $vars);
}
/**
* 模板变量赋值
* @access protected
* @param mixed $name 要显示的模板变量
* @param mixed $value 变量的值
* @return void
*/
public function assign($name, $value = '')
{
$this->initView();
$this->view->assign($name, $value);
}
/**
* 初始化模板引擎
* @access protected
* @param string $engine 引擎名称
* @param array $config 引擎参数
* @return void
*/
public function engine($engine, $config = [])
{
$this->initView();
$this->view->engine($engine, $config);
}
}

View File

@@ -471,7 +471,7 @@ trait Auto
* @param array $auto 自动完成设置
* @return Auto
*/
public function auto($auto, $rule = null)
public function auto($auto = [], $rule = null)
{
$this->options['auto'] = $auto;
return $this;
@@ -483,7 +483,7 @@ trait Auto
* @param array $validate 自动验证设置
* @return Auto
*/
public function validate($validate, $rule = null)
public function validate($validate = [], $rule = null)
{
$this->options['validate'] = $validate;
return $this;