Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:43:31+00:00 2026-05-17T19:43:31+00:00

Really quick and simple question but I can’t find a decent answer to this

  • 0

Really quick and simple question but I can’t find a decent answer to this – What is the best way to pass data from a controller to a block in Magento.

Incase it makes a difference, I am loading the layout as follows:

 $this->loadLayout(array('default', 'myModule_default'));

    $this->_initLayoutMessages('customer/session')
         ->_initLayoutMessages('catalog/session')
         ->renderLayout();

I should add, that I have been using the registry as follows:

In the controller:

Mage::register('data', $data);

In the block:

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

Not sure if this is the best way to do it though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:43:31+00:00Added an answer on May 17, 2026 at 7:43 pm

    You don’t.

    In Magento’s MVC approach, it’s not the responsibility of the controller to set variables for the view (in Magento’s case, the view is Layout and blocks). Controllers set values on Models, and then Blocks read from those same models. In Magento’s view of the world, having a Block relying on the controller doing a specific thing is tight coupling, and should be avoided.

    Your controller’s job is to do certain things to Models, and then tell the system it’s layout rendering time. That’s it. It’s your Layout/Blocks job to display an HTML page in a certain way depending on the state of the system’s Models.

    So, if I wanted to emulate traditional PHP MVC behaviors I’d

    1. Create a simple Model class the inherits from Varien_Object

    2. In the controller, instantiate that object using the Mage::getSingleton('foo/bar')

    3. Set values on the Model using the magic getter/setters (you get these in objects that inherit from Varien_Object), or setData, etc.

    4. In the Blocks, instantiate the Model again with a Mage::getSingleton('foo/bar') and read the values back.

    When you instantiate a Model with Mage::getSingleton(...) Magento will instantiate the object as a singleton. So, if you re-instantiate an object (again with Mage::getSingleton('foo/bar')) you’re getting back the same object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really simple question - how do I do a search to find all records
Maybe there is already a question about this subject, but I couldn't find it.
Hopefully this is a really quick one ;) I have written a lexer /
a quick, simple question from me about for-loops. Situation I'm currently writing some high-performance
I realize that the answer to this question is likely quite obvious (if somewhat
In terms of quick dynamically typed languages, I'm really starting to like Javascript, as
Really my question has more to do with the server-side scrubbing of html that's
I really like DevX components, but they are pretty expensive, maybe anyone knows free
I really should upgrade to Firefox 3, but I'm very dependent on Firebug working
This isn't a school assignment or anything, but I realize it's a mostly academic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.