Search code examples
magentomagento-1.5magento-1.6

Magento does not load config.xml properly and getResourceModel returns false


PLEASE!!! I'm stuck with this problem for about a month.

My original problem is Mage::getResourceModel() returns false. I tried everything and couldn't succeed.

Then I started to trace the core classes which relate to the getResourceModel() function.

I end up in Config.php _getResourceModelFactoryClassName() function, which reads the XML from $this->_xml->global->models object.

I var_dump that XML and found out that other module has _resource attribute, but my module doesn't have it.

["weee"]=>
 object(Mage_Core_Model_Config_Element)#143 (2) {
    ["class"]=>
    string(15) "Mage_Weee_Model"
    ["resourceModel"]=>
    string(13) "weee_resource"
  }
  ["weee_resource"]=>
  object(Mage_Core_Model_Config_Element)#144 (3) {
    ["class"]=>
    string(24) "Mage_Weee_Model_Resource"
    ["deprecatedNode"]=>
    string(11) "weee_mysql4"
    ["entities"]=>
    object(Mage_Core_Model_Config_Element)#150 (2) {
      ["tax"]=>
      object(Mage_Core_Model_Config_Element)#175 (1) {
       ["table"]=>
        string(8) "weee_tax"
      }
      ["discount"]=>
      object(Mage_Core_Model_Config_Element)#172 (1) {
        ["table"]=>
       string(13) "weee_discount"
      }
    }
 }

  ["module"]=>
  object(Mage_Core_Model_Config_Element)#146 (2) {
    ["class"]=>
    string(12) "Namespace_Module_Model"
    ["resourceModel"]=>
    string(11) "module_resource"
  }

In above code ["module"] is my custom module and it doesn't come with it's resource like ["weee_resource"]

<global>
    <models>
        <module>
            <class>Namespace_Module_Model</class>
            <resourceModel>module_resource</resourceModel>
        </module>
    </models>
    <module_resource>
        <class>Namespace_Module_Model_Resource</class>
        <deprecatedNode>cb_mysql4</deprecatedNode>
        <entities>
            <payment>
                <table>acs_transaction</table>
            </payment>
        </entities>
    </module_resource>

Thanks.


Solution

  • There is no module_resource NODE in config.xml

        </models>
        <module_resource>
    

    this declaration is wrong your modules_resource needs to go under models node

    <global>
        <models>
            <your_module>
                <class>Namespace_Module_Model</class>
                <resourceModel>your_module_resource</resourceModel>
            </your_module>
            <your_module_resource >
            <class>Namespace_Module_Model_Resource</class>
            <deprecatedNode>cb_mysql4</deprecatedNode>
            <entities>
                <payment>
                    <table>acs_transaction</table>
                </payment>
            </entities>
        </your_module_resource >
        </models>
    

    after that you can define resources and database tables in

    <global>
        <resources>
    

    node