1

I have created one module for banner. Its working well. In backend, I have an option to add banner image and set active or not.Initially, I have created a table with the name "banner" for save banner records.

Now I would like to change the table name like chilly_banner. I have created "chilly_banner" table manually in DB and inserted some records.

In admin banner grid, I want to show the collections from this table. I don't have any idea, how to do it. But i have tried like this in _prepareCollection() method,

$collection = Mage::getModel('banner/chilly_banner')->getCollection(); 

And in model file _init() method changed banner into chilly_banner as like above.

But I got an error like

 Fatal error: Call to a member function getCollection() on a non-object
 in ../app/code/local/Chilly/Banner/Block/Adminhtml/Banner/Grid.php on
 line 18

Have any idea how to change table name in grid collections and also want change the table name in saveAction() method too?

I'm eagarly awaiting for your response..

2

Darji, According to magento Model table is not required to same of table

As you told that

you table was banner and you have change it to  chilly_banner.

So you need to change just table name at config.xml

<entities>
    <yourmodule>
        <table>yourtable</table>
    </yourmodule>
</entities>

** Just Like: **

<entities>
    <banner>
        <table>chilly_banner</table>
    </banner>
</entities>

And you can access this table without change model name

Mage::getModel('banner/banner')->getCollection()
  • Thank you for your response. Its working. Thank you again. – DRAJI Jan 9 '15 at 10:21
  • If this step only enough,and i have been using 2 table in my module, how to tell which table need to take in prepare collection method? – DRAJI Jan 9 '15 at 10:24
  • create a question, i will give u solution – Amit Bera Jan 9 '15 at 10:27
  • I have created another thread for my further doubt magento.stackexchange.com/questions/51674/… – DRAJI Jan 9 '15 at 10:51

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.