0

This is the content of the Grid.php file class Mynamespace_Mymodule_Block_Adminhtml_Banner_Grid extends

Mage_Adminhtml_Block_Widget_Grid
{ 
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('mymodule/banner_collection');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
}

this is the content of the Mynamespace/Mymodule/Model/Mysql4/Banner/Collection.php

class Mynamespace_Mymodule_Model_Mysql4_Banner_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    protected function _construct()
    {  
        echo 11111; exit();
        $this->_init('mynamespace_mymodule/tablename'); 
    }  
}

The table from db is called mynamespace_mymodule_tablename This is the content from the config.xml in which I guess smth is wrong

<global>
    <models>
            <mynamespace_mymodule>
                <class>Mynamespace_Mymodule_Model</class>
                <resourceModel>mynamespace_mymodule_mysql4</resourceModel>
            </mynamespace_mymodule>
            <mynamespace_mymodule_mysql4>
                <class>Mynamespace_Mymodule_Model_Mysql4</class>
                <entities>
                    <mynamespace_mymodule_tablename>
                        <table>mynamespace_mymodule_tablename</table>
                    </mynamespace_mymodule_tablename>
                </entities>
            </mynamespace_mymodule_mysql4>
        </models>
</global>

1 Answer 1

1

You don't need to have the namespace_modulename in your entity definition in config.xml file, try with this code instead :

<global>
    <models>
            <mynamespace_mymodule>
                <class>Mynamespace_Mymodule_Model</class>
                <resourceModel>mynamespace_mymodule_mysql4</resourceModel>
            </mynamespace_mymodule>
            <mynamespace_mymodule_mysql4>
                <class>Mynamespace_Mymodule_Model_Mysql4</class>
                <entities>
                    <tablename>
                        <table>mynamespace_mymodule_tablename</table>
                    </tablename>
                </entities>
            </mynamespace_mymodule_mysql4>
        </models>
</global>

Also, when calling from Grid file, call to your model collection needs to modified as

Mage_Adminhtml_Block_Widget_Grid
{ 
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('mynamespace_mymodule/banner_collection');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
}

as defined in your config.xml file.

4
  • It is the same, to get the big picture what I want to achieve is this article: markshust.com/2012/07/05/…. I followed each step. BUt I get blocked with the collection Nov 4, 2015 at 14:31
  • I added one more thing, take a look.
    – Prateek
    Nov 4, 2015 at 14:41
  • ok now its getting to Mynamespace_myModule_Model_Mysql4_Banner_Collection, in the constructor, but I got this error message: dbModel read resource does not implement Zend_Db_Adapter_Abstract Nov 4, 2015 at 14:45
  • Although, that asks for a separate question, have you actually used that code ? You need to have either Banner or Tablename entity, both can not go along.
    – Prateek
    Nov 4, 2015 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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