【发布时间】:2015-05-08 07:00:19
【问题描述】:
我想在销售 -> 交易 -> 视图中放置一个新块。所以我创建了一个新块并将这个块添加到模板中。
web/app/design/adminhtml/default/company/layout/local.xml
<adminhtml_sales_transactions_view>
<reference name="content">
<block type="company_module/adminhtml_sales_transactions_error_grid" name="sales_transactions.error.grid" as="error_grid"/>
</reference>
</adminhtml_sales_transactions_view>
web/app/code/local/company/module/Block/Adminhtml/Sales/Transactions/Error/Grid.php
class Comapny_Module_Block_Adminhtml_Sales_Transactions_Error_Grid extends Mage_Adminhtml_Block_Sales_Transactions_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('transactionErrorGrid');
$this->setPagerVisibility(false);
$this->setFilterVisibility(false);
}
....
该类看起来像 web/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail/Grid.php。
/web/app/design/adminhtml/default/company/template/sales/transactions/detail.phtml
<?php echo $this->getChildHtml('error_grid') ?>
为什么没有显示新块?
编辑:
好的,我检查了 exeption.log 发现了这个:
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Company_Module_Block_Adminhtml_Sales_Transactions_Error_Grid' in /var/www/html/web/app/Mage.php:595
Stack trace:
#0 /var/www/html/web/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /var/www/html/web/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('company_module...', Array)
#2 /var/www/html/web/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('company_module...', 'error_grid')
#3 /var/www/html/web/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('company_module...', 'error_grid')
我对此进行了调试,发现getGroupedClassName函数中的web/app/code/core/Mage/Core/Model/Config.php有问题。 magento 从配置中加载 groupType ,这是空的。所以这个函数在我的类名之前添加了一个 Mage_ 并且这个 Mage-Class 不存在。
任何想法如何解决这个问题?
【问题讨论】:
-
这行
<?php echo $this->getChildHtml('error_grid') ?>是在哪里添加的?在哪个文件中? -
在 /web/app/design/adminhtml/default/company/template/sales/transactions/detail.phtml
-
你能把 details.php 中的
echo "hello";作为静态文本吗?它有呼应吗? -
echo "hello" 工作正常,所以模板正在渲染但块类没有被调用
-
能否请您参考一下并确认您没有遗漏任何步骤 -> inchoo.net/magento/custom-reference-structural-block