PHP MVC在本地工作,但上载到主机时失败 [英] PHP MVC works locally but when uploaded to host fails

查看:56
本文介绍了PHP MVC在本地工作,但上载到主机时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在localhost/myweb上一切正常,但是当我将文件夹myweb上载到我的public_html目录时,出现错误:

Everything is working fine on localhost/myweb but when i upload the folder myweb to my public_html directory i get error:

[16-Sep-2012 18:32:55] PHP Warning:  Unexpected character in input:  '\' (ASCII=92)  
state=1 in /home1/programw/public_html/myweb/index.php on line 7

[16-Sep-2012 18:32:55] PHP Parse error:  syntax error, unexpected T_STRING in /home1
/programw/public_html/myweb/index.php on line 7

在我的index.php第7行上有以下代码:

on my index.php line 7 has this code:

   $app = new Core\Bootstrap();

我知道与\斜杠有关,但是我无法弄清楚该如何解决.

i know something has to do with \ slash but i cant figure out what or how to fix it.

有人可以帮我吗?我也使用.htaccess,在.htaccess中,我有以下内容:

can anyone help me please? I also use .htaccess and inside .htaccess i have the following:

   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

解决方案

我刚刚发现\斜杠和命名空间仅在PHP 5.3中受支持,并且由于某种原因,我的主机未将其PHP更新到5.3.如果有人知道在5.2上工作的方法,我将非常感激.

i just found out that \ slash and namespacing is only supported in PHP 5.3 and my hosting for some reason didnt update their PHP to 5.3. If anyone knows a way around it to work on 5.2 i will really appreciate it.

推荐答案

该代码仅在PHP 5.3及更高版本中有效.您的服务器可能仍在运行PHP 5.2

The code will only work in PHP 5.3 and above. Your server is probably still running PHP 5.2

您可以最简单地通过phpinfo()进行检查;或phpversion();

You can check this most simply through phpinfo(); or phpversion();

要解决此问题,您需要删除名称空间(这可能是外部框架的一项大工作)或将服务器升级到PHP 5.3或更高版本(请注意5.2已经很旧了!)

To fix, you'll need to remove the namesapces (which may be a big job with an external framework) or upgrade the server to PHP 5.3 or above (note that 5.2 is pretty old!)

这篇关于PHP MVC在本地工作,但上载到主机时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆