I am working with a module that fetches data from two database tables. This data should appear in my admin module. Can anyone provide me with a tutorial for this ??
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Please proceed as follows :
You must locate following method in your adminhtml folder of module. and then collect the query and perform a join as follows :
protected function _prepareCollection() {
$collection = Mage::getModel('modulename/modelname')->getCollection();
$collection->getSelect()
->join(/*perform a join here...*/ );
$this->setCollection($collection);
return parent::_prepareCollection();
}
After this youu can add more column based on the data eturned.
I hope you know how to join a table, else please comment so i can provide you examples for it.
Update
Example of join in magento
$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->join( array('order_item'=> sales_flat_order_item), 'order_item.order_id = main_table.entity_id', array('order_item.sku'));
回答2:
There is lot of tutorials are available in internet for this. But anyway you can follow this link. CLICK_ME . This a module creator. You can build your own module and download it. This is the simplest way to understand magento module functionality. Just build your module, download it, analyze, wanna some change..? Again your build or edit ..Thats it..!