1

form

<input  type="text"  class="input-text required-entry validate-number form-control validate-zero-or-greater" id= "checkout-cart-credit-amount-textboxone"  title="<?php echo $this->__('Gift Card Credit') ?>" name="customer_creditone" />

controller

public function getTextValueAction ()
    {
    $input_amount = $this->getRequest()->getParam('customer_creditone');
    //echo $input_amount.'<br>';

    $this->_redirect('checkout/cart');
    }

controller is working fine me. how to call controller variable to phtml file

0

3 Answers 3

7

you can pass variable from controller like

$this->getLayout()->getBlock('block.name')->assign('somestring', $variable)

and in phtml you can simply use like

<?php echo $variable ?>

5

You can do it by Mage registry :

Mage::register('custom_value', $monthly_budget);

and then get it in phtml :

$monthly_budget = Mage::registry('custom_value');

Another way using session :

In controller set value:

Mage::getSingleton('core/session')->setYourDataVal($data);

In phtml get Value:

$data = Mage::getSingleton('core/session')->getYourDataVal(); 
16
  • i did not get solution .... Jan 11, 2017 at 6:02
  • i used in phtml file <?php $data = Mage::getSingleton('core/session')->setEndBalance($data); echo $data; ?> Jan 11, 2017 at 6:03
  • and in controller Mage::getSingleton('core/session')->setEndBalance($data); Jan 11, 2017 at 6:03
  • In controller Mage::getSingleton('core/session')->setEndBalance($data); and in phtml <?php echo Mage::getSingleton('core/session')->getEndBalance(); ?>
    – Arunendra
    Jan 11, 2017 at 6:05
  • i did not get solution Jan 11, 2017 at 6:12
3

You can set variable to block and use that block to phtml file and get attribute value

Use below code in controller file:

$this->getLayout()->createBlock("modulename/blockname")->setYourattribute($value);

Use below code in template file:

echo $this->getLayout()->createBlock("modulename/blockname")->getYourattribute();
2
  • i am using attribute bro ....i have fetched value from input box now i want to call it on phtml file Jan 11, 2017 at 6:13
  • get val in controller and add above code in controller Jan 11, 2017 at 6:29

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