4

I am trying to pull data from a table. To do this I have used

mage::getModel('module/model')->getData

this has returned an empty array, but i can't work out why as the table i am calling holds data.

There is a discrepancy between this model

class Ps_Prefs_Model_Prefsformelements
extends Mage_Core_Model_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements');
}

}

class Ps_Prefs_Model_Resource_Prefsformelements
extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements', 'idform_elements');
}
}

class Ps_Prefs_Model_Resource_Prefsformelements_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
    $this->_init('ps_prefs/prefsformelements');
}
}

and other models in my module. That descripency lies in the namespace_module/... part of the call. as you can see this model uses namespace_module/... while my other models work fine with just module/... I have tried run the above code using just module/... but I get the error can't retrieve entity config but if I try to run the other using this namespace_module/... I start throwing errors why?

I had considered my config but if that is the case why am I not getting errors when I use namespace_module/... and why wont it work when I make it conform to the other models?

===

EDIT

===

<config>
...
  <global>        
    <models>
        <prefs>
            <class>Ps_Prefs_Model</class>
            <resourceModel>prefs_resource</resourceModel>
        </prefs>

        <prefs_resource>
            <class>Ps_Prefs_Model_Resource</class>
            <entities>
                <prefs>
                    <table>prefcentre</table>
                </prefs>
                <prefsemail>
                    <table>prefcentre_options</table>
                </prefsemail>
                <prefsform>
                    <table>pref_form_elements</table>
                </prefsform>
            </entities>
        </prefs_resource>
    </models>
  ...
</global>
...
</config>
  • did you call load before getData? Mage::getModel('module/model')->load(3)->getData(); – Marius Nov 1 '13 at 14:03
  • I hadnt but now I have I get function load() on a non-object. What is wrong with the code for the model? – tony09uk Nov 1 '13 at 14:18
  • please paste the config.xml section where the models are defined. Everything between <models></models> – Marius Nov 1 '13 at 14:19
  • I assume you call your model like this Mage::getModel('prefs/something_here')->load(3). Make sure the class Ps_Prefs_Model_Something_Here exists. – Marius Nov 1 '13 at 14:26
  • Sorry, I trying to make the question flow better, obviously I failed. I use mage::getModel('prefs/prefsformelements') to call the model and I have three files for it, the model, the resource model and the collection, which are what I've post above. could the discrepancy I mentioned have anything to do with the problem? – tony09uk Nov 1 '13 at 14:35
4

I think the problem is that you do not have a definition for the table prefs/prefsformelements. If you look at how the init for the resource works it takes the following:

/**
 * Standard resource model initialization
 *
 * @param string $mainTable
 * @param string $idFieldName
 * @return Mage_Core_Model_Resource_Abstract
 */
protected function _init($mainTable, $idFieldName)
{
    $this->_setMainTable($mainTable, $idFieldName);
}

So looking at this and your config.xml you are missing the table that matches prefsformelements but your have others that you might have mixed up the names for.

<prefsformelements>
    <table>pref_form_elements</table>
</prefsformelements>
-1

Use Mage::getModel instead of mage::getModel.

  • 1
    That won't make a difference. Class names are not case sensitive in PHP and Mage.php file is not autoloaded. So you can use Mage, mage, even mAgE. – Marius Jul 14 '14 at 10:57
  • Sorry, yes, I must have had my brain in Perl mode. :) – Doug McLean Oct 2 '14 at 12:58

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.