I'm developing news extension for Magento following official Guide by Magento and book "Magento PHP Developers Guide".
In the book there are registry entities, items and type - and I think this will be a good practice for the future to add maybe Categories to the News extension. For now I just have Item table that has only news items in it.
According to the book I created the folder structure and placed my files like this:
-Model
--Mysql4
---Item
----Collection.php
---Item.php
--Resource
----Setup.php
--Item.php
in the official guide there's:
-Model
--Resource
---Item
----Collection.php
---Item.php
--Item.php
- What is the difference between these two? Are they both EAV?
I have setup everything (installer scripts) following the book and it worked just fine. Now I have Controller, Block and template file and I'm trying to display the data from the database.
My config.xml looks like this:
<global>
<models>
<gott_news>
<class>Gott_News_Model</class>
<resourceModel>gott_news_mysql4</resourceModel>
</gott_news>
<gott_news_mysql4>
<entities>
<item>
<table>gott_news_item</table>
</item>
</entities>
</gott_news_mysql4>
</models>
<resources>
<gott_news_setup>
<setup>
<module>Gott_News</module>
<class>Gott_News_Model_Resource_Setup</class>
</setup>
</gott_news_setup>
</resources>
Following the book it retrives data from DB like this:
$collection = Mage::getModel('gott_news/item')->getCollection();
the guide does it:
$newsCollection = Mage::getResourceModel('gott_news/item_collection');
$newsCollection->prepareForList($this->getCurrentPage);
This prepareForList() function is located in the Collection.php file. I actually should end up this prepareForList()
to pass a variable of currentPage
The Problem:
Neither works for me. It doesn't get any results from DB. and when I use prepareForList()
it says it's non-object
In the book, there's also
<resources>
<mdg_giftregistry_setup>
<setup>
<module>Mdg_Giftregistry</module>
<class>Mdg_Giftregistry_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mdg_giftregistry_setup>
<mdg_giftregistry_write>
<connection>
<use>core_write</use>
</connection>
</mdg_giftregistry_write>
<mdg_giftregistry_read>
<connection>
<use>core_read</use>
</connection>
</mdg_giftregistry_read>
</resources>
Is this needed to get data from DB?
In the indexController.php indexAction()
I'm trying to get Data but nothing is being returned:
$blogpost = Mage::getModel('gott_news/item')->getCollection();
What should I do to make it work???