0

I am new in magento. I facing a problem that i want to pass my values from my controller to my view page. But I don't know the syntax. Please anybody help me. This is my controller: -

<?php 
class Test_Mymodule_IndexController extends Mage_Core_Controller_Front_Action 
{
    public function indexAction() 
    { 
         $this->loadLayout(); 
         $this->renderLayout(); 
    }

    public function calculateAction()
    {
        $request = $this->getRequest();
         if($this->getRequest()->isPost()) 
         {
             $printdata = $request->getPost();

         }
         else
         {


         }

         $helloworld = Mage::getModel("test_mymodule/results");

             $helloworld->helloworld("helloworld");              

    } 
}

I want to display the value of $helloworld to my view name "calculate".

3

Magento uses magic get and set methods so in perfect magento world you would have controller -> block (extending mage_core_block_template ) -> view (template is either set from block instance or from layout) and then you could use the set and get methods from $this context

in controller:

$yourblockObject = $this->getLayout()->generateBlock('yourblock')->setSomething($value);

in template and block instance:

$this->getSomething(); 

however from your code example you should have a method "helloworld" in your model (object) that would accept a single parameter (that you have set to be string "helloworld" in your example)

if you have defined your layout rules in xml for your controller layout handler then you can get the defined blocks directly from layout and you can skip the generation syntax:

$this->getLayout()->getBlock('blockname');
  • thanks for your reply, i have not make any block for this but i have a .phtml file under "app/design/frontend/magento-foundation/default/template/mymodule" calculate.phtml – user2114575 Dec 2 '13 at 11:55
  • so either use the core block and assign this template dynamically or generate your own block and assign a template to this – Anton S Dec 2 '13 at 12:00
  • hi @user2114575, did u find any ways to do it? – Sushivam Nov 6 '16 at 10:40

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.