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');
?>
  • 写回答

2条回答 默认 最新

  • double0201 2014-06-19 16:02
    关注

    Instead of Mage::getBaseUrl use $root = Mage::getBaseDir();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?