2

I am using an extension where I need to pass the variable is moving from block class back to model, I have used session it works sometime but not uniformly, Is there any other way to pass it,

Thanks in advance,

Anil
  • 43
  • 1
  • 11
  • Do you use that model in the block in question? Can you give an example? Some code maybe... – Marius Sep 27 '13 at 07:01

2 Answers2

3

try using Magento’s Registry Pattern

The three registry methods are

Mage::register   
Mage::unregister   
Mage::registry 

The register method is how you set a global-like variable.

Mage::register('some_name', $var);

Then, later in the request execution, (from any method), you can fetch your variable back out

$my_var = Mage::registry('some_name');

Finally, if you want to make you variable unavailable, you can use the unregister method to remove it from the registry.

Mage::unregister('some_name');

Source

epynic
  • 1,124
  • 2
  • 14
  • 26
  • Its sort of coupon code restriction, where the extension is asking the user to input points and based on the calculation, passing the value back to the model. I have tried core/session also but that does work only once the initial value is passed. The session perhaps is not able to set the initial value, its complex at least for me – Anil Sep 27 '13 at 11:54
  • Just Try it in the Magento’s Registry Pattern method as said above – epynic Sep 27 '13 at 12:01
  • Thanks a lot for the prompt response. When I try to use registry from Model to use in block it is working fine, however if I try and process the value back to model through registry it does not. May be I have gotn a bit confused. But Anyways thanks for the prompt response. – Anil Sep 27 '13 at 15:53
  • Hey , why dont you try out a combination as said by @Fantus , and do check out http://stackoverflow.com/questions/4006183/magento-passing-data-between-a-controller-and-a-block ,let me try and prompt you back – epynic Sep 28 '13 at 03:59
3

If you can use the Model as a singleton, you can try this:

 Mage::getSingleton('yourmodule/yourmodel')->setStuff('xxxx');

and later

 Mage::getSingleton('yourmodule/yourmodel')->getStuff();

if you don't know what singletons are you should maybe try the registry approach from epynic to prevent problems.

Justus Krapp
  • 1,116
  • 9
  • 10