4

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');
    }
}
16

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

  • Marius thanks for your reply. I have tried to add prefcentre after the / in the Ps_Prefcentre_Model_Mysql4_Preferences file, but I recieved the same error. Could you please offer any further advice – tony09uk Jul 24 '13 at 8:38
  • You should add it in the collection model Ps_Prefcentre_Model_Mysql4_Preferences_Collection. – Marius Jul 24 '13 at 8:44
  • I have now got it working, looks like i will have to spend sometime understanding why. Could you offer any advice on question 1. best ways to de-bug magento projects? – tony09uk Jul 24 '13 at 10:16
  • maybe this helps for debugging: magento.stackexchange.com/questions/428/… – Marius Jul 24 '13 at 10:37
  • @Marius I am exactly having the same issue on live site (at local and on stage its working fine) I even added table PK in collection as you mentioned above but still getting the same issue. in config .... <csvheaders> <table>csv_file_headers</table> </csvheaders> .... in collection $this->_init("fileimport/csvheaders", "csvfileheaders_id"); Everything seems to be fine but on live server getting this error. error on live a:5:{i:0;s:51:"Can't retrieve entity config: fileimport/csvheaders";i:1;s:4970:"#0 – Hassan Ali Shahzad Feb 24 '16 at 22:45
1

The exception is thrown in Mage_Core_Model_Resource::getTableName() as Marius suggested and there can be multiple reasons for that because the method is used in many places in the Magento codebase.

Besides your config XML file you must pay attention to data stored in database - in your case I suspect your custom entity type (check the eav_entity_type table) to be improperly configured in DB - most probably an empty or misconfigured entity_table column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.