更新核心

This commit is contained in:
thinkphp
2015-03-27 15:38:46 +08:00
parent 9df7ecab9a
commit 7bb958636e
10 changed files with 100 additions and 77 deletions

View File

@@ -29,6 +29,9 @@ defined('EXT') OR define('EXT', '.php');
defined('MODEL_LAYER') OR define('MODEL_LAYER', 'model'); defined('MODEL_LAYER') OR define('MODEL_LAYER', 'model');
defined('VIEW_LAYER') OR define('VIEW_LAYER', 'view'); defined('VIEW_LAYER') OR define('VIEW_LAYER', 'view');
defined('CONTROLLER_LAYER') OR define('CONTROLLER_LAYER', 'controller'); defined('CONTROLLER_LAYER') OR define('CONTROLLER_LAYER', 'controller');
defined('VAR_MODULE') OR define('VAR_MODULE', 'm');
defined('VAR_CONTROLLER') OR define('VAR_CONTROLLER', 'c');
defined('VAR_ACTION') OR define('VAR_ACTION', 'a');
defined('APP_DEBUG') OR define('APP_DEBUG', false); // 是否调试模式 defined('APP_DEBUG') OR define('APP_DEBUG', false); // 是否调试模式
defined('ENV_PREFIX') OR define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀 defined('ENV_PREFIX') OR define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀

View File

@@ -1,12 +1,9 @@
<?php <?php
return [ return [
'app_debug' => true, // 调试模式
'app_status' => 'debug',// 应用模式状态 'app_status' => 'debug',// 应用模式状态
'var_module' => 'm', // 模块变量名
'var_controller' => 'c', // 控制器变量名
'var_action' => 'a', // 操作变量名
'var_pathinfo' => 's', // PATHINFO变量名 用于兼容模式 'var_pathinfo' => 's', // PATHINFO变量名 用于兼容模式
'extra_config_list' => [],
'pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', 'pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL',
'pathinfo_depr' => '/', // pathinfo分隔符 'pathinfo_depr' => '/', // pathinfo分隔符
'require_module' => true, // 是否显示模块 'require_module' => true, // 是否显示模块
@@ -15,9 +12,10 @@ return [
'default_action' => 'index', // 默认操作名 'default_action' => 'index', // 默认操作名
'action_suffix' => '', // 操作方法后缀 'action_suffix' => '', // 操作方法后缀
'url_model' => 1, // URL模式 'url_model' => 1, // URL模式
'url_request_uri' => 'REQUEST_URI', // 获取当前页面地址的系统变量 默认为REQUEST_URI
'base_url' => $_SERVER["SCRIPT_NAME"], // 基础URL路径 'base_url' => $_SERVER["SCRIPT_NAME"], // 基础URL路径
'url_html_suffix' => '.html', 'url_html_suffix' => '.html',
'url_params_bind' => false, // url变量绑定 'url_params_bind' => TRUE, // url变量绑定
'exception_tmpl' => THINK_PATH.'Tpl/think_exception.tpl',// 异常页面的模板文件 'exception_tmpl' => THINK_PATH.'Tpl/think_exception.tpl',// 异常页面的模板文件
'error_tmpl' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认错误跳转对应的模板文件 'error_tmpl' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认错误跳转对应的模板文件
'success_tmpl' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认成功跳转对应的模板文件 'success_tmpl' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认成功跳转对应的模板文件

View File

@@ -44,8 +44,9 @@ class App {
// 监听app_init // 监听app_init
Hook::listen('app_init'); Hook::listen('app_init');
define('COMMON_PATH', APP_PATH . $config['common_module'].'/');
// 初始化公共模块 // 初始化公共模块
define('COMMON_PATH', APP_PATH . $config['common_module'].'/');
self::initModule(COMMON_PATH,$config); self::initModule(COMMON_PATH,$config);
// 应用URL调度 // 应用URL调度
@@ -58,13 +59,12 @@ class App {
if(!preg_match('/^[A-Za-z](\/|\w)*$/',CONTROLLER_NAME)){ // 安全检测 if(!preg_match('/^[A-Za-z](\/|\w)*$/',CONTROLLER_NAME)){ // 安全检测
$instance = false; $instance = false;
}elseif($config['action_bind_class']){ }elseif($config['action_bind_class']){
// 操作绑定到类:模块\Controller\控制器\操作 // 操作绑定到类:模块\controller\控制器\操作
$layer = CONTROLLER_LAYER; if(is_dir(MODULE_PATH.CONTROLLER_LAYER.'/'.CONTROLLER_NAME)){
if(is_dir(MODULE_PATH.$layer.'/'.CONTROLLER_NAME)){ $namespace = MODULE_NAME.'\\'.CONTROLLER_LAYER.'\\'.CONTROLLER_NAME.'\\';
$namespace = MODULE_NAME.'\\'.$layer.'\\'.CONTROLLER_NAME.'\\';
}else{ }else{
// 空控制器 // 空控制器
$namespace = MODULE_NAME.'\\'.$layer.'\\_empty\\'; $namespace = MODULE_NAME.'\\'.CONTROLLER_LAYER.'\\empty\\';
} }
$actionName = strtolower(ACTION_NAME); $actionName = strtolower(ACTION_NAME);
if(class_exists($namespace.$actionName)){ if(class_exists($namespace.$actionName)){
@@ -161,8 +161,18 @@ class App {
}else{ }else{
// 检测配置文件 // 检测配置文件
if(is_file($path . 'config' . EXT)) { if(is_file($path . 'config' . EXT)) {
$config = Config::set(include $path . 'config' . EXT); $config = Config::set(include $path . 'config' . EXT );
} }
// 检测额外配置
if($config['extra_config_list']){
foreach($config['extra_config_list'] as $conf){
if(is_file($path . $conf . EXT)) {
$config = Config::set(include $path . $conf . EXT );
}
}
}
// 加载应用状态配置文件 // 加载应用状态配置文件
if($config['app_status'] && is_file($path . $config['app_status'] . EXT)) { if($config['app_status'] && is_file($path . $config['app_status'] . EXT)) {
$config = Config::set(include $path . $config['app_status'] . EXT); $config = Config::set(include $path . $config['app_status'] . EXT);
@@ -197,7 +207,7 @@ class App {
// 检测域名部署 // 检测域名部署
if(!IS_CLI && isset($config['sub_domain_deploy']) && $config['sub_domain_deploy']) { if(!IS_CLI && isset($config['sub_domain_deploy']) && $config['sub_domain_deploy']) {
Route::checkDomain($config); Route::checkDomain();
} }
// 监听path_info // 监听path_info
@@ -233,8 +243,8 @@ class App {
} }
$paths = explode($config['pathinfo_depr'], __INFO__,2); $paths = explode($config['pathinfo_depr'], __INFO__,2);
// 获取URL中的模块名 // 获取URL中的模块名
if($config['require_module'] && !isset($_GET[$config['var_module']])) { if($config['require_module'] && !isset($_GET[VAR_MODULE])) {
$_GET[$config['var_module']] = array_shift($paths); $_GET[VAR_MODULE] = array_shift($paths);
$_SERVER['PATH_INFO'] = implode('/', $paths); $_SERVER['PATH_INFO'] = implode('/', $paths);
} }
} }
@@ -242,6 +252,9 @@ class App {
$_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix']? '/\.('.trim($config['url_html_suffix'],'.').')$/i' : '/\.'.__EXT__.'$/i', '', $_SERVER['PATH_INFO']); $_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix']? '/\.('.trim($config['url_html_suffix'],'.').')$/i' : '/\.'.__EXT__.'$/i', '', $_SERVER['PATH_INFO']);
} }
// URL常量
define('__SELF__',strip_tags($_SERVER[$config['url_request_uri']]));
// 获取模块名称 // 获取模块名称
define('MODULE_NAME', defined('BIND_MODULE')? BIND_MODULE : self::getModule($config)); define('MODULE_NAME', defined('BIND_MODULE')? BIND_MODULE : self::getModule($config));
@@ -257,21 +270,21 @@ class App {
throw new Exception('module not exists :' . MODULE_NAME); throw new Exception('module not exists :' . MODULE_NAME);
} }
// 路由检测和控制器、操作解析 // 路由检测和控制器、操作解析
Route::check($_SERVER['PATH_INFO'],$config); Route::check($_SERVER['PATH_INFO'],$config['pathinfo_depr']);
// 获取控制器名 // 获取控制器名
define('CONTROLLER_NAME', strip_tags(strtolower(isset($_GET[$config['var_controller']]) ? $_GET[$config['var_controller']] : $config['default_controller']))); define('CONTROLLER_NAME', strip_tags(strtolower(isset($_GET[VAR_CONTROLLER]) ? $_GET[VAR_CONTROLLER] : $config['default_controller'])));
// 获取操作名 // 获取操作名
define('ACTION_NAME', strip_tags(strtolower(isset($_GET[$config['var_action']]) ? $_GET[$config['var_action']] : $config['default_action']))); define('ACTION_NAME', strip_tags(strtolower(isset($_GET[VAR_ACTION]) ? $_GET[VAR_ACTION] : $config['default_action'])));
unset($_GET[$config['var_action']], $_GET[$config['var_controller']], $_GET[$config['var_module']]); unset($_GET[VAR_ACTION], $_GET[VAR_CONTROLLER], $_GET[VAR_MODULE]);
//保证$_REQUEST正常取值 //保证$_REQUEST正常取值
$_REQUEST = array_merge($_POST, $_GET , $_COOKIE); $_REQUEST = array_merge($_POST, $_GET , $_COOKIE);
} }
static private function getModule($config){ static private function getModule($config){
$module = strtolower(isset($_GET[$config['var_module']]) ? $_GET[$config['var_module']] : $config['default_module']); $module = strtolower(isset($_GET[VAR_MODULE]) ? $_GET[VAR_MODULE] : $config['default_module']);
if($maps = $config['url_module_map']) { if($maps = $config['url_module_map']) {
if(isset($maps[$module])) { if(isset($maps[$module])) {
// 记录当前别名 // 记录当前别名

View File

@@ -52,7 +52,7 @@ class Config {
static public function get($name=null,$range='') { static public function get($name=null,$range='') {
$range = $range ? $range : self::$range; $range = $range ? $range : self::$range;
// 无参数时获取所有 // 无参数时获取所有
if (empty($name)) { if (empty($name) && isset(self::$config[$range])) {
return self::$config[$range]; return self::$config[$range];
} }
$name = strtolower($name); $name = strtolower($name);
@@ -98,8 +98,4 @@ class Config {
} }
} }
// 获取某个作用域的配置列表
static public function getRange($rang){
return isset(self::$config[$range]) ? self::$config[$range] : null;
}
} }

View File

@@ -26,8 +26,9 @@ class Controller {
$this->view = new View(); $this->view = new View();
//控制器初始化 //控制器初始化
if(method_exists($this, '_initialize')) if(method_exists($this, '_initialize')){
$this->_initialize(); $this->_initialize();
}
} }
/** /**
@@ -114,6 +115,18 @@ class Controller {
exit($data); exit($data);
} }
/**
* Action跳转(URL重定向 支持指定模块和延时跳转
* @access protected
* @param string $url 跳转的URL表达式
* @param array $params 其它URL参数
* @return void
*/
protected function redirect($url,$params=[]) {
$url = U($url,$params);
header('Location: ' . $url);
}
/** /**
* 操作错误跳转的快捷方法 * 操作错误跳转的快捷方法
* @access protected * @access protected

View File

@@ -10,7 +10,6 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think; namespace think;
use think\Config;
class Loader { class Loader {
// 类名映射 // 类名映射

View File

@@ -87,7 +87,7 @@ class Route {
} }
// 检测子域名部署 // 检测子域名部署
static public function checkDomain($config=[]){ static public function checkDomain(){
// 开启子域名部署 支持二级和三级域名 // 开启子域名部署 支持二级和三级域名
if(!empty(self::$domain)) { if(!empty(self::$domain)) {
$rules = self::$domain; $rules = self::$domain;
@@ -124,7 +124,7 @@ class Route {
exit; exit;
} }
if(is_array($rule)) { if(is_array($rule)) {
$_GET[$config['var_module']] = $rule[0]; $_GET[VAR_MODULE] = $rule[0];
if(isset($rule[1])) { // 传入参数 if(isset($rule[1])) { // 传入参数
parse_str($rule[1], $parms); parse_str($rule[1], $parms);
if(isset($panDomain)) { if(isset($panDomain)) {
@@ -137,19 +137,19 @@ class Route {
$_GET = array_merge($_GET,$parms); $_GET = array_merge($_GET,$parms);
} }
}else{ }else{
$_GET[$config['var_module']] = $rule; $_GET[VAR_MODULE] = $rule;
} }
} }
} }
} }
// 检测URL路由 // 检测URL路由
static public function check($regx,$config) { static public function check($regx,$depr='/') {
// 优先检测是否存在PATH_INFO // 优先检测是否存在PATH_INFO
if(empty($regx)) $regx = '/' ; if(empty($regx)) $regx = '/' ;
// 分隔符替换 确保路由定义使用统一的分隔符 // 分隔符替换 确保路由定义使用统一的分隔符
if('/' != $config['pathinfo_depr']){ if('/' != $depr){
$regx = str_replace($config['pathinfo_depr'], '/', $regx); $regx = str_replace($depr, '/', $regx);
} }
if(isset(self::$map[$regx])) { // URL映射 if(isset(self::$map[$regx])) { // URL映射
return self::parseUrl(self::$map[$regx]); return self::parseUrl(self::$map[$regx]);
@@ -190,7 +190,7 @@ class Route {
self::invokeRegx($route, $matches); self::invokeRegx($route, $matches);
exit; exit;
} }
return self::parseRegex($matches, $route, $regx,$config); return self::parseRegex($matches, $route, $regx);
}else{ // 规则路由 }else{ // 规则路由
$len1 = substr_count($regx, '/'); $len1 = substr_count($regx, '/');
$len2 = substr_count($rule, '/'); $len2 = substr_count($rule, '/');
@@ -213,13 +213,13 @@ class Route {
self::invokeRule($route, $var); self::invokeRule($route, $var);
exit; exit;
} }
return self::parseRule($rule, $route, $regx,$config); return self::parseRule($rule, $route, $regx);
} }
} }
} }
} }
} }
return self::parseUrl($regx,$config); return self::parseUrl($regx);
} }
/** /**
@@ -269,22 +269,22 @@ class Route {
} }
// 解析模块的URL地址 [模块/]控制器/操作 // 解析模块的URL地址 [模块/]控制器/操作
static private function parseUrl($url,$config=[]) { static private function parseUrl($url) {
if('/' == $url) { if('/' == $url) {
return ; return ;
} }
$paths = explode('/', $url); $paths = explode('/', $url);
if(!defined('BIND_MODULE') && !isset($_GET[$config['var_module']])) { if(!defined('BIND_MODULE') && !isset($_GET[VAR_MODULE])) {
$_GET[$config['var_module']] = array_shift($paths); $_GET[VAR_MODULE] = array_shift($paths);
} }
if(!defined('BIND_CONTROLLER') && !isset($_GET[$config['var_controller']])) { if(!defined('BIND_CONTROLLER') && !isset($_GET[VAR_CONTROLLER])) {
$_GET[$config['var_controller']] = array_shift($paths); $_GET[VAR_CONTROLLER] = array_shift($paths);
} }
if($paths){ if($paths){
$_GET[$config['var_action']] = array_shift($paths); $_GET[VAR_ACTION] = array_shift($paths);
} }
// 解析剩余的URL参数 // 解析剩余的URL参数
@@ -297,7 +297,7 @@ class Route {
// 解析规范的路由地址 // 解析规范的路由地址
// 地址格式 [控制器/操作?]参数1=值1&参数2=值2... // 地址格式 [控制器/操作?]参数1=值1&参数2=值2...
static private function parseRoute($url,$config=[]) { static private function parseRoute($url) {
$var = []; $var = [];
if(false !== strpos($url, '?')) { // [控制器/操作?]参数1=值1&参数2=值2... if(false !== strpos($url, '?')) { // [控制器/操作?]参数1=值1&参数2=值2...
$info = parse_url($url); $info = parse_url($url);
@@ -310,12 +310,12 @@ class Route {
} }
if(isset($path)) { if(isset($path)) {
$action = array_pop($path); $action = array_pop($path);
$_GET[$config['var_action']] = '[rest]'==$action ? REQUEST_METHOD : $action; $_GET[VAR_ACTION] = '[rest]'==$action ? REQUEST_METHOD : $action;
if(!empty($path)) { if(!empty($path)) {
$_GET[$config['var_controller']] = array_pop($path); $_GET[VAR_CONTROLLER] = array_pop($path);
} }
if(!empty($path)) { if(!empty($path)) {
$_GET[$config['var_module']] = array_pop($path); $_GET[VAR_MODULE] = array_pop($path);
} }
} }
return $var; return $var;
@@ -361,7 +361,7 @@ class Route {
// 外部地址中可以用动态变量 采用 :1 :2 的方式 // 外部地址中可以用动态变量 采用 :1 :2 的方式
// 'news/:month/:day/:id'=>array('News/read?cate=1','status=1'), // 'news/:month/:day/:id'=>array('News/read?cate=1','status=1'),
// 'new/:id'=>array('/new.php?id=:1',301), 重定向 // 'new/:id'=>array('/new.php?id=:1',301), 重定向
static private function parseRule($rule, $route, $regx,$config) { static private function parseRule($rule, $route, $regx) {
// 获取路由地址规则 // 获取路由地址规则
$url = is_array($route) ? $route[0] : $route; $url = is_array($route) ? $route[0] : $route;
// 获取URL地址中的参数 // 获取URL地址中的参数
@@ -392,7 +392,7 @@ class Route {
exit; exit;
}else{ }else{
// 解析路由地址 // 解析路由地址
$var = self::parseRoute($url,$config); $var = self::parseRoute($url);
// 解析路由地址里面的动态参数 // 解析路由地址里面的动态参数
$values = array_values($matches); $values = array_values($matches);
foreach ($var as $key => $val){ foreach ($var as $key => $val){
@@ -424,7 +424,7 @@ class Route {
// 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式 // 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式
// '/new\/(\d+)\/(\d+)/'=>array('News/read?id=:1&page=:2&cate=1','status=1'), // '/new\/(\d+)\/(\d+)/'=>array('News/read?id=:1&page=:2&cate=1','status=1'),
// '/new\/(\d+)/'=>array('/new.php?id=:1&page=:2&status=1','301'), 重定向 // '/new\/(\d+)/'=>array('/new.php?id=:1&page=:2&status=1','301'), 重定向
static private function parseRegex($matches, $route, $regx,$config) { static private function parseRegex($matches, $route, $regx) {
// 获取路由地址规则 // 获取路由地址规则
$url = is_array($route) ? $route[0] : $route; $url = is_array($route) ? $route[0] : $route;
$url = preg_replace('/:(\d+)/e', '$matches[\\1]', $url); $url = preg_replace('/:(\d+)/e', '$matches[\\1]', $url);
@@ -433,7 +433,7 @@ class Route {
exit; exit;
}else{ }else{
// 解析路由地址 // 解析路由地址
$var = self::parseRoute($url,$config); $var = self::parseRoute($url);
// 解析剩余的URL参数 // 解析剩余的URL参数
$regx = substr_replace($regx, '', 0, strlen($matches[0])); $regx = substr_replace($regx, '', 0, strlen($matches[0]));
if($regx) { if($regx) {

View File

@@ -50,10 +50,8 @@ class Template {
* 架构函数 * 架构函数
* @access public * @access public
*/ */
public function __construct($config=[]){ public function __construct(array $config=[]){
if(!empty($config)) { $this->config = array_merge($this->config, empty($config) ? (array)Config::get('template') : $config );
$this->config = array_merge($this->config,$config);
}
$this->config['taglib_begin'] = $this->stripPreg($this->config['taglib_begin']); $this->config['taglib_begin'] = $this->stripPreg($this->config['taglib_begin']);
$this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']); $this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']);
$this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']); $this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']);

View File

@@ -13,14 +13,6 @@ namespace think;
class Url { class Url {
static public function param($num,$default=''){
$paths = explode(Config::get('url_pathinfo_depr'),trim($_SERVER['PATH_INFO'],'/'));
return isset($paths[$num])?$paths[$num]:$default;
}
static public function route($route){
}
/** /**
* URL组装 支持不同URL模式 * URL组装 支持不同URL模式
* @param string $url URL表达式格式'[分组/模块/操作#锚点@域名]?参数1=值1&参数2=值2...' * @param string $url URL表达式格式'[分组/模块/操作#锚点@域名]?参数1=值1&参数2=值2...'
@@ -30,6 +22,7 @@ class Url {
* @return string * @return string
*/ */
static public function build($url='',$vars='',$suffix=true,$domain=false) { static public function build($url='',$vars='',$suffix=true,$domain=false) {
$config = Config::get();
// 解析URL // 解析URL
$info = parse_url($url); $info = parse_url($url);
$url = !empty($info['path'])?$info['path']:ACTION_NAME; $url = !empty($info['path'])?$info['path']:ACTION_NAME;
@@ -49,10 +42,10 @@ class Url {
$domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.')); $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.'));
}elseif($domain===true){ }elseif($domain===true){
$domain = $_SERVER['HTTP_HOST']; $domain = $_SERVER['HTTP_HOST'];
if(Config::get('app_sub_domain_deplay') ) { // 开启子域名部署 if($config['app_sub_domain_deplay'] ) { // 开启子域名部署
$domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.');
// '子域名'=>array('项目[/分组]'); // '子域名'=>array('项目[/分组]');
foreach (Config::get('app_sub_domain_rules') as $key => $rule) { foreach ($config['app_sub_domain_rules'] as $key => $rule) {
if(false === strpos($key,'*') && 0=== strpos($url,$rule[0])) { if(false === strpos($key,'*') && 0=== strpos($url,$rule[0])) {
$domain = $key.strstr($domain,'.'); // 生成对应子域名 $domain = $key.strstr($domain,'.'); // 生成对应子域名
$url = substr_replace($url,'',0,strlen($rule[0])); $url = substr_replace($url,'',0,strlen($rule[0]));
@@ -74,7 +67,7 @@ class Url {
} }
// URL组装 // URL组装
$depr = Config::get('pathinfo_depr'); $depr = $config['pathinfo_depr'];
if($url) { if($url) {
if(0=== strpos($url,'/')) {// 定义路由 if(0=== strpos($url,'/')) {// 定义路由
$route = true; $route = true;
@@ -90,27 +83,27 @@ class Url {
$url = trim($url,$depr); $url = trim($url,$depr);
$path = explode($depr,$url); $path = explode($depr,$url);
$var = []; $var = [];
$var[Config::get('var_action')] = !empty($path)?array_pop($path):ACTION_NAME; $var[VAR_ACTION] = !empty($path)?array_pop($path):ACTION_NAME;
if(!defined('BIND_CONTROLLER')){ if(!defined('BIND_CONTROLLER')){
$var[Config::get('var_controller')] = !empty($path)?array_pop($path):CONTROLLER_NAME; $var[VAR_CONTROLLER] = !empty($path)?array_pop($path):CONTROLLER_NAME;
} }
if(!defined('BIND_MODULE')){ if(!defined('BIND_MODULE')){
$var[Config::get('var_module')] = !empty($path)?array_pop($path):MODULE_NAME; $var[VAR_MODULE] = !empty($path)?array_pop($path):MODULE_NAME;
} }
} }
} }
if(Config::get('url_model') == 0) { // 普通模式URL转换 if($config['url_model'] == 0) { // 普通模式URL转换
$url = Config::get('base_url').'?'.http_build_query(array_reverse($var)); $url = $config['base_url'].'?'.http_build_query(array_reverse($var));
if(!empty($vars)) { if(!empty($vars)) {
$vars = urldecode(http_build_query($vars)); $vars = urldecode(http_build_query($vars));
$url .= '&'.$vars; $url .= '&'.$vars;
} }
}else{ // PATHINFO模式或者兼容URL模式 }else{ // PATHINFO模式或者兼容URL模式
if(isset($route)) { if(isset($route)) {
$url = Config::get('base_url').'/'.rtrim($url,$depr); $url = $config['base_url'].'/'.rtrim($url,$depr);
}else{ }else{
$url = Config::get('base_url').'/'.implode($depr,array_reverse($var)); $url = $config['base_url'].'/'.implode($depr,array_reverse($var));
} }
if(!empty($vars)) { // 添加参数 if(!empty($vars)) { // 添加参数
foreach ($vars as $var => $val){ foreach ($vars as $var => $val){
@@ -118,7 +111,7 @@ class Url {
} }
} }
if($suffix) { if($suffix) {
$suffix = $suffix===true?Config::get('url_html_suffix'):$suffix; $suffix = $suffix===true?$config['url_html_suffix']:$suffix;
if($pos = strpos($suffix, '|')){ if($pos = strpos($suffix, '|')){
$suffix = substr($suffix, 0, $pos); $suffix = substr($suffix, 0, $pos);
} }

View File

@@ -10,7 +10,6 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think; namespace think;
use think\Exception;
class View { class View {
protected $engine = null; // 模板引擎实例 protected $engine = null; // 模板引擎实例
@@ -34,6 +33,11 @@ class View {
'engine_type' => 'think', 'engine_type' => 'think',
]; ];
public function __construct(array $config = []){
$this->config = array_merge($this->config, empty($config)? (array)Config::get('view') : $config);
$this->engine($this->config['engine_type']);
}
/** /**
* 模板变量赋值 * 模板变量赋值
* @access public * @access public
@@ -59,9 +63,15 @@ class View {
$this->config[$name] = $value; $this->config[$name] = $value;
} }
public function __construct(array $config = []){ /**
* 设置视图参数
* @access public
* @param array $config 视图参数
* @return View
*/
public function config(array $config=[]){
$this->config = array_merge($this->config, $config); $this->config = array_merge($this->config, $config);
$this->engine($this->config['engine_type']); return $this;
} }
/** /**