thinkPHP online automatic loading exception and repair method example analysis_php example

WBOY
Release: 2023-03-03 06:50:01
Original
1103 people have browsed it

本文实例讲述了thinkPHP线上自动加载异常与修复方法。分享给大家供大家参考,具体如下:

项目遇到一个奇怪的问题,本地代码正常,服务器上却不正常。

经过测试,应该是自动加载出了问题,尝试了各种方法,

1.手动加载,发现好麻烦,没完没了。

2.自己写自动加载,写不出来,尴尬。

3.修改配置,使其支持自动加载,发现还是不行。

后来进行调试,

发现本地支持

import('@.ORG.OSS\OssClient');
import('@.ORG.OSS\Core\OssUtil');

Copy after login

而服务器上,不支持这种斜杠的方式,却支持.的方式

后来就把thinkphp核心代码,进行调整。

// 根据自动加载路径设置进行尝试搜索
$paths =  explode(',',C('APP_AUTOLOAD_PATH'));
foreach ($paths as $path){
  $class = str_replace("\\",".",$class);
  // dump($class);
  if(import($path.'.'.$class)){
    // dump($path.'.'.$class);
    // 如果加载类成功则返回
    return ;
  }
}

Copy after login

经过这个小小的动作,可以了,服务器可以使用OSS了。

不容易啊!

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《php常用函数与技巧总结》、《smarty模板入门基础教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!