Question

A question I've been meaning to ask for ages, more theoretical than anything else.

I'm fully versed in developing Extensions using the normal Magento module file structure. I've noticed though when looking at some of the Mage 'extensions', that some contain a /Controller directory. Whats the purpose of these controllers and how do the differ to the ones used normally within the /controllers dir?

I can see the names are structured differently, so I'm gathering they're auto-loaded in a different way, but what purpose do /Controller classes serve?

Thanks all

Was it helpful?

Solution

The difference is in the autoloading, as you have mentioned. In general files that are in /Controller are Abstract (or parent) classes from which classes in /controllers inherit.

Magento isn't built to be aware of the /Controller directory - it's more a matter of convention. Class names hint where to find these parents on disk and the autoloader locates them. You'll see this in Mage_Sales:

class Mage_Sales_OrderController extends Mage_Sales_Controller_Abstract

Here, the sales module locates controllers within app/code/core/Mage/Sales/controllers and the loaded controller says to the autoloader to locate it's parent in app/code/core/Mage/Sales/Controller.

This is done to provide separation of concerns and to allow concrete controller classes to inherit common functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top