instance() public static method

初始化视图
public static instance ( array $engine = [], array $replace = [] ) : object
$engine array 模板引擎参数
$replace array 字符串替换参数
return object
Exemplo n.º 1
0
 /**
  * 架构函数 初始化视图类 并采用内置模板引擎
  * @access public
  */
 public function initView()
 {
     // 模板引擎参数
     if (is_null($this->view)) {
         $this->view = \think\View::instance(Config::get());
         // 只能这样写,不然view会冲突
     }
 }
Exemplo n.º 2
0
 /**
  * 架构函数
  * @access public
  */
 public function __construct()
 {
     $this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));
     // 控制器初始化
     if (method_exists($this, '_initialize')) {
         $this->_initialize();
     }
     // 前置操作方法
     if ($this->beforeActionList) {
         foreach ($this->beforeActionList as $method => $options) {
             is_numeric($method) ? $this->beforeAction($options) : $this->beforeAction($method, $options);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 操作错误跳转的快捷方法
  * @access public
  * @param mixed $msg 提示信息
  * @param string $url 跳转的URL地址
  * @param mixed $data 返回的数据
  * @param integer $wait 跳转等待时间
  * @return void
  */
 public function error($msg = '', $url = null, $data = '', $wait = 3)
 {
     $code = 0;
     if (is_numeric($msg)) {
         $code = $msg;
         $msg = '';
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => is_null($url) ? 'javascript:history.back(-1);' : $url, 'wait' => $wait];
     $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
     if ('html' == $type) {
         $result = View::instance(Config::get('template'), Config::get('view_replace_str'))->fetch(Config::get('dispatch_error_tmpl'), $result);
     }
     Response::instance()->send($result, $type);
 }
Exemplo n.º 4
0
 /**
  * 架构函数
  * @param Request $request Request对象
  * @access public
  */
 public function __construct(Request $request = null)
 {
     if (is_null($request)) {
         $request = Request::instance();
     }
     $this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));
     $this->request = $request;
     // 控制器初始化
     $this->_initialize();
     // 前置操作方法
     if ($this->beforeActionList) {
         foreach ($this->beforeActionList as $method => $options) {
             is_numeric($method) ? $this->beforeAction($options) : $this->beforeAction($method, $options);
         }
     }
 }
Exemplo n.º 5
0
Arquivo: Jump.php Projeto: GDdark/cici
 /**
  * 操作错误跳转的快捷方法
  * @access protected
  * @param mixed $msg 提示信息
  * @param string $url 跳转的URL地址
  * @param mixed $data 返回的数据
  * @param integer $wait 跳转等待时间
  * @return void
  */
 protected function error($msg = '', $url = null, $data = '', $wait = 3)
 {
     $code = 0;
     if (is_numeric($msg)) {
         $code = $msg;
         $msg = '';
     }
     if (is_null($url)) {
         $url = 'javascript:history.back(-1);';
     } else {
         $url = preg_match('/^(https?:|\\/)/', $url) ? $url : Url::build($url);
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait];
     $type = $this->getResponseType();
     if ('html' == strtolower($type)) {
         $result = ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))->fetch(Config::get('dispatch_error_tmpl'), $result);
     }
     $response = Response::create($result, $type);
     throw new HttpResponseException($response);
 }
Exemplo n.º 6
0
 /**
  * 操作错误跳转的快捷方法
  * @access public
  * @param mixed $msg 提示信息
  * @param mixed $data 返回的数据
  * @param mixed $url 跳转的URL地址
  * @param mixed $wait 跳转等待时间
  * @return mixed
  */
 public static function error($msg = '', $data = '', $url = '', $wait = 3)
 {
     $code = 0;
     if (is_numeric($msg)) {
         $code = $msg;
         $msg = '';
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait];
     $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
     if ('html' == $type) {
         $result = \think\View::instance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
     }
     self::type($type);
     return $result;
 }
Exemplo n.º 7
0
/**
 * 渲染模板输出
 * @param string $template 模板文件
 * @param array $vars 模板变量
 * @return string
 */
function V($template, $vars)
{
    return \think\View::instance(\think\Config::get())->fetch($template, $vars);
}
Exemplo n.º 8
0
/**
 * 渲染模板输出
 * @param string $template 模板文件
 * @param array $vars 模板变量
 * @return string
 */
function view($template = '', $vars = [])
{
    return View::instance(Config::get('template'), Config::get('view_replace_str'))->fetch($template, $vars);
}
Exemplo n.º 9
0
Arquivo: View.php Projeto: GDdark/cici
 /**
  * 处理数据
  * @access protected
  * @param mixed $data 要处理的数据
  * @return mixed
  */
 protected function output($data)
 {
     // 渲染模板输出
     return ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))->fetch($data, $this->vars, $this->replace);
 }
Exemplo n.º 10
0
 /**
  *  测试引擎设置
  * @return  mixed
  * @access public
  */
 public function testGetThemePath()
 {
     $view_instance = \think\View::instance();
     $method = new \ReflectionMethod('\\think\\View', 'getThemePath');
     $method->setAccessible(true);
     $this->assertEquals('/theme_name/', $method->invoke($view_instance));
 }
Exemplo n.º 11
0
 /**
  *  测试引擎设置
  * @return  mixed
  * @access public
  */
 public function testParseTemplate()
 {
     $view_instance = \think\View::instance();
     $view_instance->theme('theme');
     $view_instance->config(['view_path' => __DIR__ . DS . 'view' . DS]);
     $method = new \ReflectionMethod('\\think\\View', 'ParseTemplate');
     $method->setAccessible(true);
     if (defined('CONTROLLER_NAME')) {
         $expect_data = __DIR__ . DS . 'view' . DS . 'theme' . DS . CONTROLLER_NAME . DS . 'template.html';
     } else {
         $expect_data = __DIR__ . DS . 'view' . DS . 'theme' . DS . 'template.html';
     }
     $this->assertEquals($expect_data, $method->invoke($view_instance, 'template'));
 }
Exemplo n.º 12
0
 public function testReplace()
 {
     $view_instance = \think\View::instance();
     $view_instance->replace('string', 'replace')->display('string');
 }
Exemplo n.º 13
0
 /**
  * 渲染内容输出
  * @access public
  * @param string $content 模板内容
  * @param array  $vars     模板输出变量
  * @param array $config     模板参数
  * @return mixed
  */
 public function display($content = '', $vars = [], $config = [])
 {
     $view = View::instance(Config::get('template'), Config::get('view_replace_str'));
     $vars = array_merge($this->data, $vars);
     return $view->display($content, $vars, $config);
 }