Magento – Unable to overcome the “Can’t retrieve entity config” error

configurationdebuggingxml

I have been working on a simple module and have been stuck with the error

Can't retrieve entity config

for too long. I am assuming that this is to do with the way I have set my config.xml files up?

The module is to extract information from a table that I have put in to the database. I guessed this would be an easy and basic project for me but i'm really struggling.

My two questions are

  1. How should I go about de-bugging projects in Magento (many of my
    problems have been with the xml). So far I have been using var_dump()
    and die() commands, is there a better way?
  2. How do I resolve this problem? (I have added my xml code below)

namespace/module/etc/config.xml

<global>
    <models>
        <prefcentre>
            <class>Ps_Prefcentre_Model</class>
            <resourceModel>prefcentre_mysql4</resourceModel>
        </prefcentre>

        <prefcentre_mysql4>
            <class>Ps_Prefcentre_Model_Mysql4</class>
            <entities>
                <prefcentre>
                    <table>prefcentre</table>
                </prefcentre>
            </entities>
        </prefcentre_mysql4>  
    </models>
    <resources>
        <prefcentre_write>
            <connection>
                <use>core_write</use>
            </connection>
        </prefcentre_write>
        <prefcentre_read>
            <connection>
                <use>core_read</use>
            </connection>
        </prefcentre_read>
    </resources>
</global>

======EDIT=====

Cache is disabled.

class Ps_Prefcentre_Model_Mysql4_Preferences
extends Mage_Core_Model_Mysql4_Abstract
{
    protected function _construct()
    {
        $this->_init('prefcentre/preferences', 'prefcentre_id');
    }
}

Best Answer

The error is generated in this method Mage_Core_Model_Resource::getTableName(). You end up in that method usually by calling the _init() method from the collection constructor.
Check how that method looks like in Ps_Prefcentre_Model_Mysql4_Prefcentre_Collection (something like that).
It should look like this:

protected function _construct()
{
    $this->_init('prefcentre/prefcentre', 'TABLE_PK_NAME_HERE');
} 

The first parameter (prefcentre/prefcentre) means the following: what's before / represents the main model class, the name of the tag right under <models> tag. In your case <prefcentre>. What's after the / is the node name under prefcentre_mysql4->entities, and before the <table> tag. In your case also prefcentre See my comments below directly on your config file section:

<models>
    <prefcentre><!-- this tag goes before the slash -->
        <class>Ps_Prefcentre_Model</class>
        <resourceModel>prefcentre_mysql4</resourceModel>
    </prefcentre>

    <prefcentre_mysql4>
        ...
        <entities>
            <prefcentre><!-- this tag goes after the slash -->
                <table>prefcentre</table>
            </prefcentre>
        </entities>
    </prefcentre_mysql4>  
</models>

And make sure you clear the cache after modifying something in config.xml

Related Topic