Pass data from controller to view in magento

It’s may be very easy for Zend framework user But, I find some magento developer fighting to pass data from controller to view.
In magento you have to create a empty model(if your mod don’t have a varient object model) which extends to varient object. Magento use magic getter magic setter so you can pass value by setAnyname() and getAnyname() thus functions will be auto defines by Zend like many other framework do. :-)

Model file:

Packname_Modulename_Model_Viewinfo extends Varien_Object{

} 

Controller function:

public function indexAction()
{	
  $bla = Mage::getSingleton('Modulename/viewinfo');
  $bla->setMsg("Thank You for your visit!");
  $this->loadLayout();
  $this->renderLayout();
}

Now in your View .phtml file add:

<?php $blas = Mage::getSingleton('Modulename/viewinfo'); ?>
<?php echo $blas->getMsg(); ?>
  • siva

    above code is not working, please clarify my problem
    model.php
    <?php

    function test(){
    $sample="test";
    }

    redirect.phtml: