我正在关注本教程。本教程不是 100% 完成的,需要用户填补一些空白。我很好。打破的部分是$collection = Mage::getModel('employee/employee')->getCollection();
。我假设这是因为我要求 Magento 调用我需要定义的客户 getCollection 方法。我浏览了一遍,似乎找不到如何创建集合文件的示例。
谁能给我举几个例子?
谢谢你。
我正在关注本教程。本教程不是 100% 完成的,需要用户填补一些空白。我很好。打破的部分是$collection = Mage::getModel('employee/employee')->getCollection();
。我假设这是因为我要求 Magento 调用我需要定义的客户 getCollection 方法。我浏览了一遍,似乎找不到如何创建集合文件的示例。
谁能给我举几个例子?
谢谢你。
1) file in **app\code\local\NCM\Employee\etc\config.xml**
<?xml version="1.0"?>
<config>
<modules>
<NCM_Employee>
<version>0.1.0</version>
</NCM_Employee>
</modules>
<frontend>
<routers>
<employee>
<use>standard</use>
<args>
<module>NCM_Employee</module>
<frontName>employee</frontName>
</args>
</employee>
</routers>
<layout>
<updates>
<employee>
<file>employee.xml</file>
</employee>
</updates>
</layout>
</frontend>
<admin>
<routers>
<employee>
<use>admin</use>
<args>
<module>NCM_Employee</module>
<frontName>employee</frontName>
</args>
</employee>
</routers>
</admin>
<adminhtml>
<menu>
<employee module="employee">
<title>Employee</title>
<sort_order>71</sort_order>
<children>
<items module="employee">
<title>Manage Items</title>
<sort_order>0</sort_order>
<action>employee/adminhtml_employee</action>
</items>
</children>
</employee>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<NCM_Employee>
<title>Employee Module</title>
<sort_order>10</sort_order>
</NCM_Employee>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<employee>
<file>employee.xml</file>
</employee>
</updates>
</layout>
</adminhtml>
<global>
<models>
<employee>
<class>NCM_Employee_Model</class>
<resourceModel>employee_mysql4</resourceModel>
</employee>
<employee_mysql4>
<class>NCM_Employee_Model_Mysql4</class>
<entities>
<employee>
<table>employee</table>
</employee>
</entities>
</employee_mysql4>
</models>
<resources>
<employee_setup>
<setup>
<module>NCM_Employee</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</employee_setup>
<employee_write>
<connection>
<use>core_write</use>
</connection>
</employee_write>
<employee_read>
<connection>
<use>core_read</use>
</connection>
</employee_read>
</resources>
<blocks>
<employee>
<class>NCM_Employee_Block</class>
</employee>
</blocks>
<helpers>
<employee>
<class>NCM_Employee_Helper</class>
</employee>
</helpers>
</global>
</config>
2) file in **app\code\local\NCM\Employee\Model\Employee.php**
class NCM_Employee_Model_Employee extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('employee/employee');
}
}
3) file in **app\code\local\NCM\Employee\Model\Mysql4\Employee.php**
class NCM_Employee_Model_Mysql4_Employee extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
$this->_init('employee/employee', 'employee_id');
}
}
4) file in **app\code\local\NCM\Employee\Model\Mysql4\Employee\Collection.php**
class NCM_Employee_Model_Mysql4_Employee_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('employee/employee');
}
}
谢谢 WojtekT。我的 etc/config.xml 中缺少这部分
<models>
<categoryrules>
<class>Rogue_CategoryRules_Model</class>
<resourceModel>categoryrules_mysql4</resourceModel>
</categoryrules>
<categoryrules_mysql4>
<class>Rogue_CategoryRules_Model_Mysql4</class>
<entities>
<rules>
<table>rogue_category_rules</table>
</rules>
</entities>
</categoryrules_mysql4>
</models>