1

I made a grid in admin for viewing all the applications received. I want to make a link in one column so when the admin clicks this link a new page will be opened. In this page I will pass the id and will fetch some data via collections. Further I have made front end form and all tables have collections. Please advice weather it is good idea to use collection queries to fetch data from db tables in the phtml file or there is some alternative to this. Remember this is not single query this contains some joins etc also.

Thanks in advance.

1

You can add a link in action column easily. Just follow the standard procedure. Just add a new action in the actions array according to your requirements. As an example, checkout the below code:

$this->addColumn('action',
        array(
            'header'    =>  Mage::helper('your_module_name')->__('Actions'),
            'width'     => '100',
            'type'      => 'action',
            'getter'    => 'getId',
            'actions'   => array(
                array(
                    'caption'   => Mage::helper('your_module_name')->__('Print'),
                    'url'       => array('base'=> '*/*/print'),
                    'field'     => 'id'
                ),
                array(
                    'caption'   => Mage::helper('brands')->__('Edit'),
                    'url'       => array('base'=> '*/*/edit'),
                    'field'     => 'id'
                )
            ),
            'filter'    => false,
            'sortable'  => false,
            'index'     => 'stores',
            'is_system' => true,
    ));

If you are using collections to fetch data from your models, then its ok, and it does not create any problem related to performance. Also note that magento does not provide any way to pass data from your controllers to a view (except by some nasty ways). So one of the way to keep the MVC pattern is to use helper classes. Also, blocks can be used.

  • Thanks, I used Mage_Adminhtml_Block_Template and defined methods here to be used in the phtml file using $this. – AbdulBasit Jan 14 '16 at 7:28
  • If the default block (named as module) is used, then you can still use $this. – Altaf Hussain Jan 14 '16 at 7:33
0

I think it's ok, just don't use this in a loop Also you can move this code in your block or model, and leave just one method call in the phtml, so it's tidy

  • Do you mean to create a function in the block, then pass the id to it and do all the db/collections manipulation and return data in array and then display array in the phtml file as per the format required ?? – AbdulBasit Jan 14 '16 at 6:58
  • There is no need to the pass the id to block methods. You can still use magento request object to fetch get or post data in block classes. – Altaf Hussain Jan 14 '16 at 7:26

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.