Magento – Magento AddTab with Form & Grid within Same Tab in Admin Module

formsgridmagento-1.8module

So I have a methodology that works fine but I have a distinct feeling there is a totally different way, more Magentoriffic way to do this.

I have an admin module with a tabbed form. In one of the tabs, I want a small form to reside just above a grid. I have done it by doing a simple append on the blocks with a period as shown below.

Works great, no errors, no exceptions, but I have not seen this methodology anywhere else in Magento.

So, I am on a quest to determine the Magento way of doing this. Here is my code:

$this->addTab('directory_content', array(
    'label'     => Mage::helper('businessdirectory')->__('Listings'),
    'title'     => Mage::helper('businessdirectory')->__('Listings'),
    'content'   => $this->getLayout()->createBlock('businessdirectory/adminhtml_directories_edit_tab_listing')->toHtml().
                   $this->getLayout()->createBlock('businessdirectory/adminhtml_directories_edit_tab_listing_grid')->toHtml()
)); 

Best Answer

What you could do is use url instead of content. This will fill the content with a call to a specific url, in this way you can then use a controller rendering layout via xml so that the whole thing becomes more expendable.

'url'       => $this->getUrl('*/*/categories', array('_current' => true)),

A perfect example of this is the catalog and how you can add categories and other products such as upselling and cross selling to products. Check out app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php and see how it is done there.

Though I am not saying that either is more "Magentoriffic"

Related Topic