cancel
Showing results for 
Search instead for 
Did you mean: 

Pass data from module to phtml file using register.

Pass data from module to phtml file using register.


Hi,

I want to pass data fetch from database to phtml file located at following location.

./app/design/frontend/default/default/template/mymodule/mymodule.phtml

I tried placing code mymodule/Block/IndexController.php and other location using

Mage::register('name-of-registry-key', $your-data);


To get data.

$var = Mage::registry('name-of-registry-key');

Where in module folder I need to place this code to be able to access from phtml file.

Also Is it good practice to get database connection phtml file to perform work using $connection = 

Mage::getModel('core/resource')->getConnection('core_read');

Any idea?

-Thanks & Regards,Shahab
1 REPLY

Re: Pass data from module to phtml file using register.

They work but they are not good practice.

To get data in tempalte, you should set data to the block which rendering this template or create a public function in that block. If the template does not have a custom block, you can use a helper.

To perform db operation, you should use model or resource model to utilize the full power of ORM.