示例#1
0
 /**
  * 架构函数 初始化视图类 并采用内置模板引擎
  * @access public
  */
 public function initView()
 {
     // 模板引擎参数
     if (is_null($this->view)) {
         $this->view = \think\View::instance(Config::get());
         // 只能这样写,不然view会冲突
     }
 }
示例#2
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);
 }
示例#3
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);
         }
     }
 }
示例#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);
         }
     }
 }
示例#5
0
文件: Jump.php 项目: 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);
 }
示例#6
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);
}
示例#7
0
文件: View.php 项目: 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);
 }
示例#8
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));
 }
示例#9
0
 public function testReplace()
 {
     $view_instance = \think\View::instance();
     $view_instance->replace('string', 'replace')->display('string');
 }
 /**
  * 随便看看
  */
 public function look()
 {
     $prefix = C('DB_PREFIX');
     $post = M('')->query("select * from {$prefix}forum_post order by rand()");
     $post = $this->forumPostModel->assignForumInfo($post);
     if (IS_POST) {
         $view = new View();
         $view->assign('posts', $post);
         $view->display(T('Forum@Index/_look'));
         exit;
     }
     $this->assign('tab', 'look');
     $this->assign('posts', $post);
     $this->display();
     //dump(D()->getLastSql());
     // dump($post);exit;
 }
示例#11
0
 /**
  * 返回封装后的API数据到客户端
  * @access public
  * @param mixed $msg 要返回的数据
  * @param mixed $data 返回的code
  * @param mixed $url 提示信息
  * @param mixed $wait 返回数据格式
  * @return void
  */
 public static function error($msg = '', $data = '', $url = '', $wait = 3)
 {
     $result = ['code' => 0, 'msg' => $msg, 'data' => $data, 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait];
     if (IS_AJAX) {
         Config::set('default_return_type', Config::get('default_ajax_return'));
     }
     if ('html' == Config::get('default_return_type')) {
         $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
     }
     return $result;
 }
示例#12
0
文件: index.php 项目: apple006/think
 public function index()
 {
     Slog::log('调试');
     $view = new View();
     return $view->fetch();
 }
示例#13
0
文件: index.php 项目: houseme/think
 public function index()
 {
     $view = new View();
     return $view->fetch();
 }
示例#14
0
文件: index.php 项目: phpsong/think
 public function index()
 {
     $view = new View();
     $view->display();
 }
 /**
  * 随便看看
  */
 public function look()
 {
     $prefix = C('DB_PREFIX');
     $sql = "select * from {$prefix}forum_post where status=1 order by rand() LIMIT 0 , " . modC('FORM_POST_SHOW_NUM_PAGE', '10', 'Forum');
     $post = M('')->query($sql);
     $post = $this->forumPostModel->assignForumInfo($post);
     if (IS_POST) {
         $view = new View();
         $view->assign('posts', $post);
         $view->display(T('Forum@Index/_look'));
         exit;
     }
     $this->assign('tab', 'look');
     $this->assign('posts', $post);
     $this->display();
 }
示例#16
0
文件: helper.php 项目: 5ini99/think
/**
 * 渲染模板输出
 * @param string $template 模板文件
 * @param array $vars 模板变量
 * @return string
 */
function V($template, $vars)
{
    return \think\View::instance(\think\Config::get())->fetch($template, $vars);
}
示例#17
0
文件: viewTest.php 项目: cnzin/think
 /**
  *  测试引擎设置
  * @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'));
 }
示例#18
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;
 }
示例#19
0
文件: Widget.php 项目: hugtale/think
 /**
  * 渲染内容输出
  * @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);
 }