dongmen1860
2014-06-19 15:40
浏览 38
已采纳

Magento - 在phtml模板文件中包含/要求php文件

In one of my magento template phtml files I am trying to include a seperate php file. When I include it I get nothing outputted and when i use require instead I get the following error

Fatal error: require(): Failed opening required 'http://www.site.co.uk/dir/test.php'
(include_path='/home/usr/public_html/app/code/local:/home/usr/public_html/app/code/community:/home/usr/public_html/app/code/core:/home/usr/public_html/lib:.:/usr/lib/php:/usr/local/lib/php') in /home/usr/public_html/app/design/frontend/theme/edits/template/review/product/view/list.phtml on line 30

The first line of the error shows the correct url path and when i go to it directly it works - it just doesn't like being included/required from the phtml template page.

I've tried the following in the phtml file (using magento's BaseURL, absolute path and the relative path):

<?php 
$root = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
require/include ($root.'dir/test.php');
?>

<?php 
require/include ('http://www.site.co.uk/dir/test.php');
?>

<?php 
require/include ('../../../../../../../../../dir/test.php');
?>

图片转代码服务由CSDN问答提供 功能建议

在我的一个magento模板phtml文件中,我试图包含一个单独的php文件。 当我包含它时我 得到任何输出,当我使用require而不是我得到以下错误

 致命错误:require():无法打开所需的'http://www.site.co.uk  /dir/test.php'
(include_path='/home/usr/public_html/app/code/local:/home/usr/public_html/app/code/community:/home/usr/public_html/app/code/  core:/ home / usr / public_html / lib:。:/ usr / lib / php:/ usr / local / lib / php')/ home / usr / public_html / app / design / frontend / theme / edits / template / 第30行上的review / product / view / list.phtml 
   
 
 

错误的第一行显示正确的url路径,当我直接转到它时,它可以工作 - 它只是不喜欢从phtml模板页面中包含/要求。

我在phtml文件中尝试了以下内容(使用magento的BaseURL,绝对路径和相对路径):

 &lt;?php 
 $ root = Mage :: getBaseUrl  (Mage_Core_Model_Store :: URL_TYPE_WEB); 
require / include($ root.'dir / test.php'); 
?&gt; 
 
&lt;?php 
require / include('http://www.site。  co.uk/dir/test.php');
?>

<?php 
require / include('../../../../../../ ..  /../../dir/test.php');
?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题