我正在开发一个自定义magento管理员后端模块,该模块将包含一个包含可以添加/编辑的项目的网格。这是我的模块结构:
/Mycompany/
---/Mymodule/
-------/Block/
-----------/Adminhtml
--------------/Manageskumappings.php
--------------/Manageskumappings/
-----------------/Grid.php
-----------------/Edit.php
-----------------/Edit/
--------------------/Form.php
-------/controllers/
-----------/Adminhtml
--------------/ManageskumappingsController.php
-------/etc/
-------/Helper/
-------/Model/
-------/sql/
这是我的模块config.xml
:
<?xml version="1.0"?>
<config>
<!-- Module Info -->
<modules>
<Mycompany_Mymodule>
<version>2.0.0</version>
</Mycompany_Mymodule>
</modules>
<!-- Module Globals -->
<global>
<!-- Register Helper -->
<helpers>
<mycompany_mymodule>
<class>Mycompany_Mymodule_Helper</class>
</mycompany_mymodule>
</helpers>
<!-- Register Models -->
<models>
<mycompany_mymodule>
<class>Mycompany_Mymodule_Model</class>
<resourceModel>mycompany_mymodule_mysql4</resourceModel>
</mycompany_mymodule>
<mycompany_mymodule_mysql4>
<class>Mycompany_Mymodule_Model_Mysql4</class>
<entities>
<skumappings>
<table>icw_ic_skumappings</table>
</skumappings>
</entities>
</mycompany_mymodule_mysql4>
</models>
<!-- Register Resource -->
<resources>
<mycompany_mymodule_setup>
<setup>
<module>Mycompany_Mymodule</module>
</setup>
</mycompany_mymodule_setup>
</resources>
</global>
<!-- Admin Router -->
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Mycompany_Mymodule after="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</Mycompany_Mymodule>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<!-- Admin Layout -->
<adminhtml>
<layout>
<updates>
<mycompany_mymodule>
<file>mycompany/mymodule.xml</file>
</mycompany_mymodule>
</updates>
</layout>
</adminhtml>
</config>
这是模块的adminhtml.xml
:
<?xml version="1.0"?>
<config>
<!-- Menu Setup -->
<menu>
<mycompany translate="title" module="mycompany_mymodule">
<title>Infinite:Connect v2</title>
<sort_order>0</sort_order>
<children>
<mycompany_mymodule_manageskumappings>
<title>Manage SKU Mappings</title>
<sort_order>1</sort_order>
<action>adminhtml/manageskumappings</action>
</mycompany_mymodule_manageskumappings>
</children>
</mycompany>
</menu>
<!-- Access Control List -->
<acl>
<resources>
<admin>
<children>
<mycompany translate="title" module="mycompany_mymodule">
<title>My Module</title>
<sort_order>1</sort_order>
<children>
<manageskumappings>
<title>Manage SKU Mappings</title>
<sort_order>1</sort_order>
</manageskumappings>
</children>
</mycompany>
</children>
</admin>
</resources>
</acl>
</config>
我创建了以下布局文件:
应用/设计/ adminhtml /默认/默认/布局/ myCompany的/ mymodule.xml
具有以下定义:
<?xml version="1.0"?>
<layout>
<!-- Manage SKU Mappings -->
<adminhtml_manageskumappings_index>
<reference name="content">
<block type="mycompany_mymodule/adminhtml_manageskumappings" name="mycompany_mymodule_manageskumappings" />
</reference>
</adminhtml_manageskumappings_index>
</layout>
这是我的网格控制器:
应用/代码/小区/ MyCompany的/ Mymodule中/控制器/ Adminhtml / ManageskumappingsController.php
使用以下代码:
<?php
class Mycompany_Mymodule_Adminhtml_ManageskumappingsController extends Mage_Adminhtml_Controller_Action
{
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')
->isAllowed('mycompany/manageskumappings');
}
protected function _initAction()
{
$this->loadLayout()
->_setActiveMenu('mycompany/mycompany_mymodule_manageskumappings')
->_title('Manage SKU Mappings');
return $this;
}
public function indexAction()
{
$this->_initAction()
->renderLayout();
}
// ... Snipped ...
我上传了代码并迁移了数据库并显示了菜单。当我进入菜单&#34; Mymodule - &gt;管理SKU映射&#34;我看到一个空白页面。
我去查看var / log / exception.log,我看到以下内容:
例外&#39; Mage_Core_Exception&#39;消息&#39;无效的块类型:Mage_Mycompany_Mymodule_Block_Adminhtml_Manageskumappings&#39;在/var/www/public_html/app/Mage.php:595
知道可能出现什么问题吗?
答案 0 :(得分:2)
我能看到的第一个错误是:你忘了注册你的积木。请将块定义部分添加到模块config.xml:
<config>
...
<global>
...
<!-- Register Blocks -->
<blocks>
<mycompany_mymodule>
<class>Mycompany_Mymodule_Block</class>
</mycompany_mymodule>
</blocks>
...
</global>
...
<config>