1

I want to send some data to header block from a controller. Tried this way. But its not working.

<?php
class Mageart_Iosapi_IndexController extends Mage_Core_Controller_Front_Action{

    public function indexAction()
    { 
        $data = "testing";
        $this->getLayout()->getBlock("header")->setData("isodata", $data);   
        $this->loadLayout();                
        $this->getLayout()->getBlock("head")->setTitle($this->__("Please Wait.."));
        $this->renderLayout(); 
        $templateImage = $this->getRequest()->getPost('template_image');
        $productId     = $this->getRequest()->getPost('product_id');
        $firstname     = $this->getRequest()->getPost('firstname');
        $lastname     = $this->getRequest()->getPost('lastname');
        $cusemail     = $this->getRequest()->getPost('cusemail');
        $password     = $this->getRequest()->getPost('password');
        $qty           = $this->getRequest()->getPost('qty');

        $arg = array(
            'template_image' => bin2hex($templateImage),
            'product_id' => bin2hex($productId),
            'firstname' => bin2hex($firstname),
            'lastname' => bin2hex($lastname),
            'cusemail' => bin2hex($cusemail),
            'password' => bin2hex($password),
            'qty' => bin2hex($qty)            
        );


        if ( (isset($firstname) || $firstname != "") && (isset($lastname) || $lastname != "")
                && (isset($cusemail) || $cusemail != "") && (isset($password) || $password != "") ) {
             $customer = $this->_loadCustomer($firstname, $lastname, $cusemail, $password);
             $this->_redirect('iosapi/index/addtocart',$arg);
        } else {
            Mage::getSingleton('core/session')->addError('Customer Details are Missing.');
            $this->_redirect('checkout/cart');
            $errorStatus = false;

        }
    }
    ...
}

In header.phtml file

<?php echo $this->getData("isodata"); ?>
2

You'll first need to load the layout

class Mageart_Iosapi_IndexController extends Mage_Core_Controller_Front_Action{

    public function indexAction()
    { 
        $data = "testing";   
        $this->loadLayout();    
        $this->getLayout()->getBlock("header")->setData("data", $data); 
        ...
    }
}

Also, I'd recommend using a less arbitrary name than data since it might cause conflicts. Try isodata for example.

| improve this answer | |
  • Thank you. But its still not giving any output. I have updated the question. – Dushan Sep 10 '15 at 10:08
  • Since you're redirecting to another page at the end of the controller method this would cause the page not to be rendered – Sander Mangel Sep 10 '15 at 10:12
  • Can you please suggest any alternative method, when its redirect and still way to get the data? – Dushan Sep 10 '15 at 10:15
1

try this

$this->loadLayout()->getLayout()->getBlock('header')
     ->setIsodata($data);

<?php echo $this->getIsodata();?>
| improve this answer | |

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.