ThinkPHP 解决模板文件大小写问题

以前使用TP3.1时,没有注意$this->display()默认解析的模板文件大小问题。现在使用TP3.2,在windows下开发没什么毛病,昨晚放在测试服务器上(阿里云CentOS LAMP),竟然报找不到模板文件错误。我的情况是:

windows下define(‘APP_DEBUG’, true) ‘URL_CASE_INSENSITIVE’ =>true。没问题。
windows下define(‘APP_DEBUG’, true) ‘URL_CASE_INSENSITIVE’ =>false。没问题。
windows下define(‘APP_DEBUG’, false) ‘URL_CASE_INSENSITIVE’ =>true。没问题。
windows下define(‘APP_DEBUG’, false) ‘URL_CASE_INSENSITIVE’ =>false。没问题。
linux下define(‘APP_DEBUG’, true) ‘URL_CASE_INSENSITIVE’ =>true。报错找不到模板文件。
linux下define(‘APP_DEBUG’, true) ‘URL_CASE_INSENSITIVE’ =>false。报错找不到模板文件。
linux下define(‘APP_DEBUG’, false) ‘URL_CASE_INSENSITIVE’ =>true。报错找不到模板文件。
linux下define(‘APP_DEBUG’, false) ‘URL_CASE_INSENSITIVE’ =>false。报错找不到模板文件。
试了网上说的各种(主要是在Application和ThinkPHP中修改URL_CASE_INSENSITIVE),对我都没用。就暂时在控制器中搜索所有$this->display(),改为$this->display(__FUNCTION__)。删除Application/Runtime。算是暂时用着。

然后开始找资料,论坛上有人提供了修改ThinkPHP中parseTemplate()的代码,但是我复制 粘贴后报语法错误,然后开始注意ThinkPHP/Library/Think/View.class.php的display()方法。

display()方法中调用了fetch()方法来解析获取模板内容,fetch()方法中调用了parseTemplate()方法来获取模板文件,parseTemplate()方法中通过$template = CONTROLLER_NAME . $depr . ACTION_NAME;来处理模板文件名为空(即display()放参数为空)下的定位规则,看到这儿,猜测ACTION_NAME是导致模板文件找不到的原因,在controller中var_dump(ACTION_NAME),果然是小写的。

 

 

然后在ThinkPHP中找到ACTION_NAME的定义,ThinkPHP/Library/Think/Dispatcher.class.php的dispatch()通过define(‘ACTION_NAME’, self::getAction($varAction));定义了ACTION_NAME的值,getAction()中通过return strip_tags(strtolower($action));的strtolower()把得到的操作/方法名转为小写返回了,把strtolower删了。

 

猜你喜欢

转载自www.cnblogs.com/programmer123/p/11674624.html