Magento: Passing variables among controller, block, hepler, model and template

Magento is a configuration-based Model-View-Controller web application system for eCommerce business.
Model:
MAGEROOT/app/code/codePool/PackageName/ModuleName/Model
View:
MageROOT/app/code/codePool/PackageName/ModuleName/Block and template files in /app/design/……
Controller:
MageROOT/app/code/codePool/PackageName/ModuleName/controllers

In Magento, controller sets values on Models, then Blocks and templates reads them from the those Models. For example, we can set a string hello by using core/session model

<?php
Mage::getSingleton('core/session')->setHello('hello');
?>

Then we can get this hello from a block or a template or anywhere else by

<?php
Mage::getSingleton('core/session')->getHello();
?>

You can use these magic setter and getter function from any model class that inherit from Varien_Object. The Mage::getSingleton(‘module/model’), it instantiate the model object as a singleton that will link to the same object if it was instantiate before. Thus, when you do setData($somedate), you can get it back by getData()

Search within Codexpedia

Custom Search

Search the entire web

Custom Search