Question

I am implementing a quotation form. I then declared a module in which I defined a phtml template containing the form, the computed price display and the javascript/ajax script.

I also have defined a block :

<?php
class Mine_Quotemodule_Block_Quoteformblock extends Mage_Core_Block_Template
{
     public function methodblock()
     {
         return 'informations de mon block !!';
     }
}
?>

and a controller

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

   public function quoteAction()
   {
     echo 'test mamethode';
    }
}
?>

In order to be able to display and update my quotation price, I need to use some vars.

I thought declaring and initializing them in the indexAction() (for default price display) and update them in quoteAction() which will be called by my form script.

Is this the good way?

if declared in indexAction, how to refer to them in quoteAction() and in the phtml?

Thank you for your help,

Alex

Was it helpful?

Solution

The global variables are set using Mage::register('variable', $variable). This variable can be called from anywhere then using $_variable = Mage::registry('variable).

If you need a session variable, you can use :

Mage::getSingleton('core/session')->setMyVariable('value of variable');

This variable can be called later with :

$variable = Mage::getSingleton('core/session')->getMyVariable();

I would say that ideally the session and global variables are set in the controllers. You can then call them anywhere.

For the variables used is the view (.phtml), the best is to set them in the block. You can then call them using $this->getVariable().

private $_variable;
public function getVariable(){
    return $_variable
} 
public function setVariable(){
    ...logic...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top