仅在生产中出现无效的块类型异常

Invalid block type exception on production only

我正在做一个项目,在我的本地机器上一切正常(OS x - 不区分大小写的文件系统)但在生产服务器上抛出异常 "Invalid block type"(Linux - 区分大小写的文件系统)。问题是我想我检查了所有文件名的正确 upper/lower 大小写。

这是堆栈跟踪:

exception 'Mage_Core_Exception' with message 'Invalid block type: Eqush_Eqush_Block_Footertop' in /www/eqush/app/Mage.php:595
Stack trace:
#0 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('eqush/footertop', Array)
#2 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('eqush/footertop', 'eqush_footertop')
#3 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('eqush/footertop', 'eqush_footertop')
#4 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 /www/eqush/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /www/eqush/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 /www/eqush/app/code/core/Mage/Catalog/controllers/CategoryController.php(148): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 /www/eqush/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Catalog_CategoryController->viewAction()
#9 /www/eqush/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('view')
#10 /www/eqush/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#11 /www/eqush/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#12 /www/eqush/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#13 /www/eqush/index.php(87): Mage::run('', 'store')
#14 {main}

这是带有布局和块的模块配置:(自定义支付模型正常工作)

<?xml version="1.0"?>
<config>
    <modules>
        <Eqush_Eqush>
            <version>0.0.1</version>
        </Eqush_Eqush>
    </modules>
    <global>
        <blocks>
            <eqush>
                <class>Eqush_Eqush_Block</class>
            </eqush>
        </blocks>
        <models>
            <eqush>
                <class>Eqush_Eqush_Model</class>
            </eqush>
        </models>
    </global>

    <default>
        <payment>
            <eqush_paypal>
                <model>eqush/paypal</model>
                <active>1</active>
                <order_status>pending</order_status>
                <title>PayPal</title>
                <sort_order>1</sort_order>
            </eqush_paypal>
        </payment>
    </default>

    <frontend>
        <layout>
            <updates>
                <eqush>
                    <file>eqush_page.xml</file>
                </eqush>
            </updates>
        </layout>
    </frontend>
</config>

这里是代码块(app/code/local/Eqush/Eqush/Block/Footertop.php)

class Eqush_Eqush_Block_Footertop extends Mage_Core_Block_Template
{}

此块的部分布局调用:(eqush_page.xml)

<reference name="footerTop">
    <block type="eqush/footertop" name="eqush_footertop" template="eqush/footer-top.phtml" before="-"></block>
</reference>

我没主意了。我搜索了很多,但没有任何帮助。我觉得一切都很好。

乍一看这是绝对正确的代码。您是否尝试清除 magento_root/var/cache 文件夹并检查?

我们来看看Mage_Core_Model_Layout (app/code/core/Mage/Core/Model/Layout.php) 第482行:

protected function _getBlockInstance($block, array $attributes=array())
{
    if (is_string($block)) {
        if (strpos($block, '/')!==false) {
            if (!$block = Mage::getConfig()->getBlockClassName($block)) {
                Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));
            }
        }
        if (class_exists($block, false) || mageFindClassFile($block)) {
            $block = new $block($attributes);
        }
    }
    if (!$block instanceof Mage_Core_Block_Abstract) {
        Mage::throwException(Mage::helper('core')->__('Invalid block type: %s', $block));
    }
    return $block;
}

在您的堆栈跟踪中,异常在第 495 行抛出,即方法中的第二个 throwException。如果您查看第 486 行:

if (!$block = Mage::getConfig()->getBlockClassName($block)) {

如果$block 为null,则抛出第一个throwException。但是由于抛出了第二个 throwException,$block 不能是 Mage_Core_Block_Abstract 的实例,也许它是一个字符串。要对此进行调试,请在第 486 行添加一个断点或转储 $block 并查看它是什么。