Sharing informations between controllers and blocks in Magento

As we know magento has quite powerful templates system. The same thing we can say about logic part. In general magento consists of about 50 modules. There is module for checkout, for customer, for cms pages etc. Module consists of few parts - beside design parts there are: components, blocks, models and  helpers. Components contains all actions that happen when the module is used.  When we have url

it means that module a must run action c in controller b.

Blocks are responsible for preparing data for templates. Each template used must have it's block. Sometimes blocks are simple, sometimes they can be more complicated. Anyway in some situations it's useful to move data from controller to block so we won't have to calculate it few times in one request.

For that we can use possibility that magento gives us - registering data.

In controller we store our data in variable called $data, we can save it to register like this:


Then in block file, you can get all this data, back using.

$data = Mage::registry('MyData');

It's a small feature that can be very useful sometimes.