我已经在这里呆了几个小时了。 Magento 一直试图从 Mage 命名空间而不是我自己的命名空间调用我的块。
错误:
/Library/WebServer/Documents/magento/app/Mage.php:594 中带有消息“无效块类型:Mage_Newcart_Block_Adminhtml_Igrid”的异常“Mage_Core_Exception”
我到处寻找试图找到问题的地方。我知道它到达了我的布局并且 handle 可以工作:
<?xml version="1.0"?>
<layout version="0.1.0">
<images_adminhtml_index_index>
<reference name="content">
<block type="newcart/adminhtml_igrid" name="adminblock" />
</reference>
</images_adminhtml_index_index>
</layout>
但是我的块(实际上是一个网格容器)不会从正确的命名空间中调用:
app/code/local/[Namespace]/Newcart/Block/Adminhtml/Igrid.php
class [Namespace]_Newcart_Block_Adminhtml_Igrid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_imagegrid';
$this->_blockGroup = 'newcart';
$this->_headerText = 'Images';
$this->_addButtonLabel = 'Add an Image';
parent::__construct();
}
protected function _prepareLayout()
{
//Mage::log($this->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
// $this->_controller . '.grid'), null, ‘layout.log’ );
$this->setChild( 'grid',
$this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
$this->_controller . '.grid')->setSaveParametersInSession(true) );
return parent::_prepareLayout();
}
}
注意:Imagegrid 是同一个目录下的一个文件。我试过 '$this->_controller = 'adminhtml_igrid';',
但是,它没有解决问题。
配置:
<?xml version="1.0"?>
<config>
<modules>
<[namespace]_Newcart>
<version>0.1.0</version>
</[namespace]_Newcart>
</modules>
<admin>
<routers>
<images>
<use>admin</use>
<args>
<module>[namespace]_Newcart</module>
<frontName>imageadmin</frontName>
</args>
</images>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<images>
<file>images.xml</file>
</images>
</updates>
</layout>
</adminhtml>
<global>
<blocks>
<[namespace]_newcart>
<class>[namespace]_Newcart_Block</class>
</[namespace]_newcart>
</blocks>
<models>
<images>
<class>[namespace]_Newcart_Model</class>
<resourceModel>image_resource</resourceModel>
</images>
<image_resource>
<class>[namespace]_Newcart_Model_Resource</class>
<entities>
<imagemodel>
<table>nw_images</table>
</imagemodel>
</entities>
</image_resource>
</models>
</global>
</config>
我到处寻找原因,但不知道还能在哪里寻找错误。请帮忙!!!
最佳答案
回答(谢谢,ivantedja!)
它应该是'newcart',而不是'[namespace]_newcart'(在blocks节点中,你不需要指定命名空间)
关于Magento 从 Mage 命名空间调用我的命名空间 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12538571/