Magento 2: Passing Variables from Controller Action to "View"

Regarding #1, the registry does still exist, very similar to what you know from Magento 1. It's just moved. See: \Magento\Framework\Registry

Add it to your constructor via dependency injection, and then you can use your familiar $registry->register($key, $value) and $registry->registry($key) methods to store/access data.

I'd recommend poking around the \Magento\Framework namespace if you haven't already. A lot of what was accessible from Mage or App before is still there, just split out.

As far as best practices, I can't answer that, but I expect the answer would be to keep as much logic out of the controller as possible. Looking at the core is probably your best bet. For instance, see the customer address edit page: Basic controller; extensive block--including pulling the address ID and loading, if necessary. They handle that directly in the block; they don't do it in the controller and then pass it around.


You should not passing Variables from Controller Action to View. Use block to for passing Variables to View (template engine).