如何诊断“无效块类型..”错误?


19

不知道如何找出这个错误,我已经搜寻了一个星期,但似乎找不到解决方法。有任何想法吗?

2013-06-10T04:04:28+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Invalid block type: ' in /home/xxxxxxx/public_html/app/Mage.php:594
Stack trace:
#0 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('', Array)
#2 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('', 'checkout.cart')
#3 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('', 'checkout.cart')
#4 /home/xxxxxxx/public_html/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 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 /home/xxxxxxx/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(159): Mage_Core_Controller_Varien_Action->loadLayout()
#9 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Checkout_CartController->indexAction()
#10 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#11 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#13 /home/xxxxxxx/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#14 /home/xxxxxxx/public_html/index.php(89): Mage::run('', 'store')
#15 {main}

Answers:


20

根据您发布的堆栈跟踪,Magento加载布局更新xml文件并使用它们创建将呈现页面HTML的块时,似乎正在发生这种情况。

这些行似乎是问题所在

#1 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('', Array)
#2 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('', 'checkout.cart')
#3 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('', 'checkout.cart')

addBlockcreateBlock_getBlockInstance方法都想到的第一个参数是一个类的别名字符串块。有点像checkout/cart。但是,在您的系统中,此字符串丢失。

->addBlock('', 'checkout.cart')

由于Magento的扩展性很强,因此有很多原因可能会发生这种情况。最常见的原因是您的catalog.xml文件已更改,因此

<block type="checkout/cart" name="checkout.cart">

缺少它的type属性。可能看起来像这样

<block name="checkout.cart">

否则可能是错字

<block typeX="checkout/cart" name="checkout.cart">

希望能有所帮助。如果问题仍然存在,请务必返回并发布正确的答案。


5
最有可能是<block name="checkout.cart">而不是<reference name="checkout.cart">。我已经在互联网上的几个主题(免费或付费)中看到了这一点。layout在主题文件夹中进行简单搜索就可以确认(或驳回)这一理论。
Marius

2
是的,reference标签不会导致调用堆栈- createBlock被调用,这意味着它是block标签。
艾伦·斯托姆

3

在原始帖子的评论帮助下,我能够找到有问题的代码!

这是引起异常的代码段:

<checkout_cart_index>
    <reference name="content">
        <block name="checkout.cart">            
            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.bottom" as="snippet_cart_bottom">
                <action method="setBlockId"><block_id>snippet_cart_bottom</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.coupon.below" as="snippet_cart_coupon_below">
                <action method="setBlockId"><block_id>snippet_cart_coupon_below</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.empty.bottom" as="snippet_cart_empty_bottom">
                <action method="setBlockId"><block_id>snippet_cart_empty_bottom</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.list.below" as="snippet_cart_list_below">
                <action method="setBlockId"><block_id>snippet_cart_list_below</block_id></action>
            </block>
        </block>
    </reference>
</checkout_cart_index>

修改后的代码不再引起异常:

<checkout_cart_index>
    <reference name="checkout.cart">        
            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.bottom" as="snippet_cart_bottom">
                <action method="setBlockId"><block_id>snippet_cart_bottom</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.coupon.below" as="snippet_cart_coupon_below">
                <action method="setBlockId"><block_id>snippet_cart_coupon_below</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.empty.bottom" as="snippet_cart_empty_bottom">
                <action method="setBlockId"><block_id>snippet_cart_empty_bottom</block_id></action>
            </block>

            <!-- Add CMS Static Block -->
            <block type="cms/block" name="snippet.cart.list.below" as="snippet_cart_list_below">
                <action method="setBlockId"><block_id>snippet_cart_list_below</block_id></action>
            </block>            
    </reference>
</checkout_cart_index>

0

我设法通过简单地删除旧块来解决我的问题。我这样做是:

Mage::log($className . ' - ' $blockName, null, 'logfile.log');在/app/code/core/Mage/Core/Model/Layout.php中的“ _generateBlock”函数中添加该行

像这样:

$block = $this->addBlock($className, $blockName);
if (!$block) {
    Mage::log($className . ' - ' $blockName, null, 'logfile.log');
    return $this;
}

然后,通过将以下行添加到主题/布局中的local.xml文件中来删除这些块

<remove name="fb8cd356f514800e782dfca09d40465d"/>
<remove name="1f0592cf88e12e898c194d5d18250c51"/>
<remove name="downloads.product"/>

希望这对某人有帮助。无法忍受我的exceptions.log文件中编写的所有废话。

更新:

我发现在/app/code/core/Mage/Core/Model/Layout.php的_generateBlock函数中,在“返回$ this”之前使用此代码

if ($_SERVER['HTTP_X_FORWARDED_FOR'] == '00.00.00.00') {
    Mage::log(Zend_Debug::dump($parentBlock, null, false), null, 'export_all_xml.log');
}

显然,如果需要,也可以将“ HTTP_X_FORWARDED_FOR”更改为“ REMOTE_ADDR”。

更新2

通过添加以下内容,最终发现我的网站存在问题:

if ($_SERVER['HTTP_X_FORWARDED_FOR'] == '00.00.00.00') {
    Mage::setIsDeveloperMode(true);
}

就在'Mage :: throwException(Mage :: helper('core')-> __('Invalid block type:%s',$ block));'之上;' 在文件'/app/code/core/Mage/Core/Model/Layout.php'中的'_getBlockInstance'函数中

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.