0

I have a form in front end that save vale in database and shown in the admin grid. I have an action button in front of each row so click of this button i want to get the rest of columns value.

I have following grid in admin:

 protected function _prepareColumns()
{
    $this->addColumn('name', array(
        'header' => Mage::helper('optfirst_reviewmycompany')->__('Name'),
        'align' => 'right',
        'width' => '10px',
        'index' => 'name',
        ));

    $this->addColumn('email', array(
        'header' => Mage::helper('optfirst_reviewmycompany')->__('Email'),
        'align' => 'left',
        'index' => 'email',
        'width' => '50px',
        ));


    $this->addColumn('comment', array(
        'header' => Mage::helper('optfirst_reviewmycompany')->__('Comments'),
        'width' => '150px',
        'index' => 'comment',
        ));

      $this->addColumn('action',
        array(
      'header' => Mage::helper('optfirst_reviewmycompany')->__('Send Email'),
      'width' => '50',
      'type' => 'action',
      'getter' => 'getId',
      'actions' => array(
             array(
                  'caption' => Mage::helper('optfirst_reviewmycompany')->__('Review Email'),
                  'url' => array('base'=> '*/*/view'),
                  'field' => 'id'
                )),
      'filter' => false,
      'sortable' => false,
      'index' => 'stores',
      'is_system' => true,
     ));

How i can do this for each row.

enter image description here

2
  • You want to display all values to admin or you want to send email? Commented Jan 7, 2017 at 16:09
  • want to send email to the ID in the column email onclik of the button in the row..
    – Xabby
    Commented Jan 7, 2017 at 16:18

1 Answer 1

0

In your controller file in which the action for loading grid page is defined, add function mentioned below.

public function viewAction(){
    $request=$this->getRequest()->getParams();
    $modelData=Mage::getModel('optfirst_reviewmycompany/contacts')->load($request['id']);//This will fetch all data corresponding to a particular id. 

    $mail = Mage::getModel('core/email')
            ->setToName($senderName)
            ->setToEmail($customerEmail)
            ->setBody($html)
            ->setSubject('Subject :')
            ->setFromEmail($senderEmail)
            ->setFromName($senderName)
            ->setType('html');
    try{
        $mail->send();
        Mage::getSingleton('core/session')->addSuccess('Mail sent successfully');
    }
    catch(Exception $error)
    {
        Mage::getSingleton('core/session')->addError($error->getMessage());
        return false;
    }
    $this->_redirect('*/*/');
}
8
  • So how it will trigger on based of each row button that is in front of each? as shown in image it is "Review Email"
    – Xabby
    Commented Jan 7, 2017 at 16:57
  • The 'actions' parameter in addColumn value will create URL like path/to/admin/controller/view/id/1/key/98awree045sdsd80. It will add entity id value in the URL. In the above example, it is '1'. This id value we are fetching using statement $id=$this->getRequest()->getParam('id'); Commented Jan 7, 2017 at 17:06
  • I got this error: Fatal error: Call to a member function load() on boolean in C:\xampp\htdocs\extension-development\app\code\community\OptFirst\ReviewMyCompany\controllers\Adminhtml\EmailsController.php on line 24
    – Xabby
    Commented Jan 7, 2017 at 17:13
  • Please provide the code that you are using to get collection for grid. Commented Jan 7, 2017 at 17:15
  • Here it is: protected function _prepareCollection() { $collection = Mage::getModel('optfirst_reviewmycompany/contacts')->getCollection(); //print_r($collection); $this->setCollection($collection); return parent::_prepareCollection(); }
    – Xabby
    Commented Jan 7, 2017 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.