Magento 从 Mage 命名空间调用我的命名空间 block

标签 magento module namespaces block

我已经在这里呆了几个小时了。 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/

相关文章:

javascript - 仅实例化一个 javascript 模块一次

module - Crystal 有静态方法吗?

javascript - 为什么将 javascript 命名空间作为函数?

namespaces - Cakephp 3 : React/zmq library namespace

magento - 如何在 Magento 订单保存中保存 tablerate_bestway 送货方式?

php - 订单网格的公司名称列

java - 如何在Eclipse中安装Web动态模块?

javascript - 如何在 Magento 网站页面上找到脚本的源文件?

php - 了解 Magento 中的 getChildHtml

r - 我是否必须导出通过::in R 有条件地导入的函数?