Example #1
0
 /**
  * 架构函数 初始化视图类 并采用内置模板引擎
  * @access public
  */
 public function initView()
 {
     // 模板引擎参数
     if (is_null($this->view)) {
         $this->view = \think\View::instance(Config::get());
         // 只能这样写,不然view会冲突
     }
 }
Example #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);
 }
Example #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);
         }
     }
 }
Example #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);
         }
     }
 }
Example #5
0
File: Jump.php Project: 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);
 }
Example #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);
}
Example #7
0
File: View.php Project: 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);
 }
Example #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));
 }
Example #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;
 }
Example #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;
 }
Example #12
0
 public function index()
 {
     Slog::log('调试');
     $view = new View();
     return $view->fetch();
 }
Example #13
0
 public function index()
 {
     $view = new View();
     return $view->fetch();
 }
Example #14
0
 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();
 }
Example #16
0
/**
 * 渲染模板输出
 * @param string $template 模板文件
 * @param array $vars 模板变量
 * @return string
 */
function V($template, $vars)
{
    return \think\View::instance(\think\Config::get())->fetch($template, $vars);
}
Example #17
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'));
 }
Example #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;
 }
Example #19
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);
 }