The problem with obtaining data from the Model (Magento Full Release - ver 1.9.2.4).

I get the model in the action controller:

$news = Mage::getModel('dev_news/news')->getCollection(); 

Then to get id do:

Then to get id do:

 foreach ($news as $item) { echo $item->getId() } 

Result:

 Fatal error: Uncaught Error: Call to a member function order() on null in /home/vitaliy/hosts/module.dev/lib/Varien/Data/Collection/Db.php:506 Stack trace: #0 

How is this a proxy? I can not find the answer.

file /etc/conf.xml

 <global> <models> <vitaliydev_news> <class>VitaliyDev_News_Model</class> <resourceModel>vitaliydev_news_resource</resourceModel> </vitaliydev_news> <vitaliydev_news_resource> <class>VitaliyDev_News_Model_Resource</class> <entities> <news> <table>news</table> </news> </entities> </vitaliydev_news_resource> </models> <resources> <vitaliydev_news_setup> <setup> <module>VitaliyDev_News</module> </setup> </vitaliydev_news_setup> </resources> </global> 

Model / News.php

 class VitaliyDev_News_Model_News extends Mage_Core_Model_Abstract { public function __construct() { parent::_construct(); $this->_init('vitaliydev_news/news'); } } 

Model / Resource / News.php

 <?php class VitaliyDev_News_Model_Resource_News extends Mage_Core_Model_Mysql4_Abstract { protected function _construct() { $this->_init('vitaliydev_news/news','news_id'); } } 

Model / Resource / News / Collection.php

 <?php class VitaliyDev_News_Model_Resource_News_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract { public function __construct() { parent::_construct(); $this->_init('vitaliydev_news/news'); } } 
  • list the model files, model resource and collections. It looks like your collection initialization is wrong. - Naumov
  • @Naumov, question edited. Models and resources are elementary, but still fail for some reason. I really need a hint, because I do not understand what the matter is ( - Maybe_V 7:18 pm
  • one
    so the __construct method does not perform initialization in the _construct method which is protected and is not a magic method. for an example you can see here as inchoo.net/magento/… - Naumov
  • @Naumov, thank you) helped - Maybe_V

0