douxing9228 2018-07-27 13:13
浏览 13

当我没有编写代码时,为什么服务器会添加双正斜杠?

I am trying to load the header file in the home class using a loader. This works on the local server and shows the whole web page.

After uploading the codes on to the server, the codes throws a fatal error

Fatal error: Uncaught LogicException: The template "common/Header" could not be found at "App/View/template//common/Header.tpl"

Looking at the error above, I notice that there is a double forward '//'

"App/View/template//common/Header.tpl"

I did not add this to the loader code. This is what is in my loader

$file = APP_DIR . 'Controllers/' . str_replace("\\", '/', $path_to_controller) . ".php";
$relative_controller = 'Controllers' . preg_replace('/[^a-zA-Z0-9]/', '', $path_to_controller);

Why is the web server adding a double forward slash on its own?

  • 写回答

1条回答 默认 最新

  • douzhang7603 2018-07-27 14:05
    关注

    Probably the $path_to_controller starts with /. In that case you can simply remove the forward slash before it:

    $file = APP_DIR . 'Controllers' . str_replace("\\", '/', $path_to_controller) . ".php";

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘