0
votes

hope that everybody is doing well. I am new to magento. I am working on magento module. I want to use grid in Admin but i need to use collections. I have created a few collection and haven't got any success in accessing any of them successfully. I want to know where i am wrong. let me share my problem with you.

my config file chunk

<models>

    <exporter>
        <class>World_Exporter_Model</class>
        <!-- 
        need to create our own resource, cant just
        use core_mysql4
        -->
        <resourceModel>exporter_mysql4</resourceModel>
    </exporter>   
<exporter_mysql4>
      <class>World_Exporter_Model_Mysql4</class>
      <entities>
             <exporter>
                        <table>profiles</table>
             </exporter>
      </entities>

</exporter_mysql4>
 </models>

My model

class World_Exporter_Model_Mysql4_Profiles extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{

    $this->_init('exporter/profiles', 'profile_id');
}
}

And my collection

 class World_Exporter_Model_Mysql4_Profiles_Collection extends    Mage_Core_Model_Mysql4_Collection_Abstract
 {
public function _construct(){
    parent::_construct();
    $this->_init('exporter/profiles');
}
 }

If you want to help me. I am great full.

(Added After getting Answer)....

    $model = Mage::getResourceModel('exporter/profiles');

    //  $model = Mage::getModel('exporter/profiles');           

    $collection = $model->getCollection();          

Fatal error: Call to undefined method World_Exporter_Model_Mysql4_Profiles::getCollection()

    //  $model = Mage::getResourceModel('exporter/profiles');

        $model = Mage::getModel('exporter/profiles');           

        $collection = $model->getCollection();

a:5:{i:0;s:47:Can't retrieve entity config: exporter/profiles";i:1;s:2542:

#0 \app\code\core\Mage\Core\Model\Resource.php(272): Mage::throwException('Can't retrieve ...')

#1 \app\code\core\Mage\Core\Model\Resource\Db\Abstract.php(284): Mage_Core_Model_Resource->getTableName('exporter/profil...')

#2 \app\code\core\Mage\Core\Model\Resource\Db\Abstract.php(247): Mage_Core_Model_Resource_Db_Abstract->getTable('profiles')

But i do have the table "profiles" in db

I will appreciate your help…

2

2 Answers

4
votes

So I finally got the answer by myself, as i haven't got enough response i got to do it by myself, many thanks to the only responder to my question, actually his answer help my solve this problem, so credit goes to him as well.

Now the solution

<exporter>
    <class>World_Exporter_Model</class>

    <resourceModel>exporter_mysql4</resourceModel>
</exporter>   
<exporter_mysql4>
  <class>World_Exporter_Model_Mysql4</class>
  <entities>
       <!-- This portion makes it stop working --> 
         <exporter>
                    <table>profiles</table>
         </exporter>
       <!-- This portion makes it stop working -->

       <!-- Replace the above highlighted portion with this portion -->
         <profiles>
                    <table>profiles</table>
         </profiles>

      <!-- Replace the above highlighted portion with this portion -->

  </entities>

 </exporter_mysql4>
</models>

So in the above code (xml) we have replaced the exporter tag with profiles

and then writing the code

class World_Exporter_Model_Profiles extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        // now profiles in this will catch the table name within profiles tags
        $this->_init('exporter/profiles');
    }
}

and it started work for me.

1
votes

It looks like you are missing the model. IF you look in your config xml, what you are calling your model is your resource model. You still need to define the actual model. Again, in your config xml, this model is already declared: <class>World_Exporter_Model</class>

The basic class should look like this:

class World_Exporter_Model_Profiles extends Mage_Core_Model_Abstract
{
    public function _construct()
    {

        $this->_init('exporter/profiles');
    }
}

and should be at /app/code/local/World/Exporter/Model/Profiles.php