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

2018-12-11 09:05:10来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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,'/');
    }

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:PHP结合AJAX简单实现投票功能

下一篇:thinkphp 使用paginate分页搜索带参数