您好,欢迎访问一九零五行业门户网

TP的module支持中文

為了讓url支持中文,例如www.xxx.com/廣州/xx 需要在emptyaction中處理捕獲到的廣州/xxxx。但是tp默認的module名稱是不支持中文的。因此需要修改tp框架的php核心文件: 
app.class.php 
修改後的代碼:
java代码  
/** * 执行应用程序 * @access public * @return void */ static public function exec() { if(!preg_match('/^[a-za-z](\w)*$/',module_name) ){ // 安全检测 $module = false; }else{ //创建action控制器实例 $group = defined('group_name') && c('app_group_mode')==0 ? group_name.'/' : ''; //$module = a($group.module_name); if(preg_match(/[\x7f-\xff]/, module_name)){//中文模式 if(in_array(module_name,c('chinese_module_name'))){ //在指定的中文內 $module = a($group.'istheempty'); }else{ _404(l('_module_not_exist_').':'.module_name); } }else{ $module = a($group.module_name); } } if(!$module) { if('4e5e5d7364f443e28fbf0d3ae744a59a' == module_name) { header(content-type:image/png); exit(base64_decode(app::logo())); } if(function_exists('__hack_module')) { // hack 方式定义扩展模块 返回action对象 $module = __hack_module(); if(!is_object($module)) { // 不再继续执行 直接返回 return ; } }else{ // 是否定义empty模块 $module = a($group.'empty'); if(!$module){ _404(l('_module_not_exist_').':'.module_name); } } } // 获取当前操作名 支持动态路由 $action = c('action_name')?c('action_name'):action_name; $action .= c('action_suffix'); try{ if(!preg_match('/^[a-za-z](\w)*$/',$action)){ // 非法操作 throw new reflectionexception(); } //执行当前操作 $method = new reflectionmethod($module, $action); if($method->ispublic()) { $class = new reflectionclass($module); // 前置操作 if($class->hasmethod('_before_'.$action)) { $before = $class->getmethod('_before_'.$action); if($before->ispublic()) { $before->invoke($module); } } // url参数绑定检测 if(c('url_params_bind') && $method->getnumberofparameters()>0){ switch($_server['request_method']) { case 'post': $vars = array_merge($_get,$_post); break; case 'put': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_get; } $params = $method->getparameters(); foreach ($params as $param){ $name = $param->getname(); if(isset($vars[$name])) { $args[] = $vars[$name]; }elseif($param->isdefaultvalueavailable()){ $args[] = $param->getdefaultvalue(); }else{ throw_exception(l('_param_error_').':'.$name); } } $method->invokeargs($module,$args); }else{ $method->invoke($module); } // 后置操作 if($class->hasmethod('_after_'.$action)) { $after = $class->getmethod('_after_'.$action); if($after->ispublic()) { $after->invoke($module); } } }else{ // 操作方法不是public 抛出异常 throw new reflectionexception(); } } catch (reflectionexception $e) { // 方法调用发生异常后 引导到__call方法处理 $method = new reflectionmethod($module,'__call'); $method->invokeargs($module,array($action,'')); } return ; }
將需要支持的中文module名稱添加到config.php chinese_module_name 配置數組中
這樣就能支持中文url解析了。
其它类似信息

推荐信息