php - 为什么我对 Magento Block 的 getTemplateFile 方法的调用返回 null?

标签 php oop magento

当我在索引 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_TemplateMage_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/

相关文章:

c# - 使用继承来创建自定义的、类型安全的、空安全的集合?

oop - Kotlin 中的 OVERRIDE_BY_INLINE

C++ 错误 C2533,构造函数 : constructors not allowed a return type

magento - SSL 错误!,您的连接已使用现代密码学加密

jquery - Magento 中 Cloud Zoom 的小产品图片?

PHP设置日期顺序并获取数据

php - 检查 PHP 5.6 中类数组常量中元素的存在

php - ini文件中的变量php

linux - Magento 1.7 - 一台服务器中的两个magento相互影响

php - 将 Unicode 数字转换为普通数字