当前位置: 移动技术网 > IT编程>开发语言>PHP > thinkphp3.2模块名如何不区分大小写?

thinkphp3.2模块名如何不区分大小写?

2018年12月11日  | 移动技术网IT编程  | 我要评论

thinkphp3.2中已配置:'url_case_insensitive' => true,对于控制器及操作名大小写都可以,但仍对于模块名的大小写就运行机制出错,
比如:http://www.xxxx.com/home 这是正常的,但换成http://www.xxxx.com/home就出错,

解决方案如下

修改 view.class.php 文件让大小写共存
替换 parsetemplate 

public function parsetemplate($template='') {
        if(is_file($template)) {
            return $template;
        }
        $depr       =   c('tmpl_file_depr');
        $template   =   str_replace(':', $depr, $template);
        // 获取当前模块
        $module   =  module_name;
        if(strpos($template,'@')){ // 跨模块调用模版文件
            list($module,$template)  =   explode('@',$template);
        }
        // 获取当前主题的模版路径
        defined('theme_path') or    define('theme_path', $this->getthemepath($module));
        // 分析模板文件规则
        if('' == $template) {
            // 如果模板文件名为空 按照默认规则定位
            $template = controller_name . $depr . action_name;
        }elseif(false === strpos($template, $depr)){
            $template = controller_name . $depr . $template;
        }
        $file   =   theme_path.$template.c('tmpl_template_suffix');
        if(c('tmpl_load_defaulttheme') && theme_name != c('default_theme') && !is_file($file)){
            // 找不到当前主题模板的时候定位默认主题中的模板
            $file   =   dirname(theme_path).'/'.c('default_theme').'/'.$template.c('tmpl_template_suffix');
        }
        //url 大小写转换
        if(!is_file($file)){
            $file = $this->get_url($file);
            if(!is_file($file)){
                 $file = $this->get_url($file,1); 
            }
        }
        return $file;
    }
    private function get_url($f,$x=''){
        $a = explode('/',$f);
        $b = count($a)-1;
        foreach ($a as $k => $v){
            if($k == $b){
                if(empty($x)){
                    $c .= ucfirst($v).'/';
                }else{
                    $c .= strtolower($v).'/';
                }
            }else{
                $c .= $v.'/';
            }
        }
        return rtrim($c,'/');
    }

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网