当我在索引 Controller 中使用以下代码时
<?php
class Nofrills_Booklayout_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$block = new Mage_Core_Block_Template();
$block->setTemplate('helloworld.phtml');
var_dump($block->getTemplateFile());
}
}
我期待这样的结果
string 'frontend/base/default/template/helloworld.phtml' (length=47)
但是,在我的系统上,我得到
null
我的系统有什么问题,它返回 null
来调用
<code>getTemplateFile</code>
或我该如何自行调试?
发生在 Magento 1.7.0.1 上。
最佳答案
作为Vinai在他的 original comment on the OP 中指出,此问题需要 tarball 来解决。
Mage_Core_Block_Abstract
的类定义必须 正在加载,否则将输出有关include()
的错误或非-对象操作,或者根本没有输出,具体取决于开发者模式。
需要注意的是getTemplateFile()
was not defined直到 Magento 1.4.1.0 .那么最有可能的问题是 Mage_Core_Block_Template
或 Mage_Core_Model_Design_Package
的版本不正确,无论是在本地还是社区代码池中以修改形式存在,或者所报告的 Magento 版本不正确。有用的输出如下:
public function indexAction()
{
ini_set('display_errors',1);
Mage::setIsDeveloperMode(true);
$block = new Mage_Core_Block_Template();
$block->setTemplate('helloworld.phtml');
$debug = new ReflectionClass($block);
echo Mage::getVersion();
Zend_Debug::dump($debug->getFileName());
Zend_Debug::dump($debug->getMethods());
}
关于php - 为什么我对 Magento Block 的 getTemplateFile 方法的调用返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11301351/