Request Flow in Magento 1 and Magento 2

Oct 26, 2017694Denis Natalevich
Request Flow in Magento 1 and Magento 2

If you’re good at Magento 1, you will be able to find substantial similarities between Magento 1 and Magento 2. First off, let’s look at the pictures showing us the paths of both Magento versions.

request flow in magento 1 and magento 2

Request flow in Magento 1.x

Magento 1.x routes all requests through index.php file which is placed in the Magento base directory. At the end of the file,

is called.

Mage:: run($code = ”, $type = ‘store’, $options = array())
Mage::run() makes the basic run time environment be set up while the request be processed. That process is started by delegating to Mage_Core_Model_App::run().

Frontend main entry point

Load base system configuration (local.xml and config.xml files) from app/etc/modules/*.xml.
Base configuration provides an ability to initialize DB connection and cache backend

Initialize active modules configuration and data

Initialize the store currently running

Load the request information into the model

Update/create versions of modules in core_resource whenever needed.

Dispatch controller


Check if there’s url rewrite as well as redirect to url

Routers check the request URL to match patterns

If a controller and action are matched, the controller file will be included, instantiated and action method will be called.

–        Process Admin scope Requests
File: app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
Class: Mage_Core_Controller_Varien_Router_Admin
–        Process Front end scope Requests
File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Class: Mage_Core_Controller_Varien_Router_Standard
–        Custom.
–        Default. Process no-route action, 404 page.
File: app/code/core/Mage/Core/Controller/Varien/Router/Default.php
Class: Mage_Core_Controller_Varien_Router_Default

The further process will be considered using a frontend controller as an example: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Class: Mage_Core_Controller_Varien_Router_Standard::match()

The “match” method sets values to module name, controller and action. Then dispatch action


–        Frontend Controller
File: app\code\core\Mage\Core\Controller\Varien\Action.php
Class: Mage_Core_Controller_Front_Action::dispatch($action)
–        Admin Controller
File: app\code\core\Mage\Adminhtml\Controller\Action.php
Class: Mage_Adminhtml_Controller_Action::dispatch($action)

Call action. Action method will instantiate and call methods on models, depending on the request

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

For the main page the following method will be called: Mage_Cms_IndexController::indexAction().

Mage_Core_Controller_Varien_Action::loadLayout ($handles = null, $generateBlocks = true, $generateXml = true)


Flushing Output

Request Flow in Magento 2.x

Similar to Magento 1, Magento 2 routes requests through index.php.

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

This method creates the instance of object manager factory

Factory method to create application instances

Runs an application

Magento\Framework\App\Bootstrap::(AppInterface $application)

When launching the app, first we determine and specify area code

Then configure object manager for definite area

As we can see, area isolation is better in Magento 2.

Init & dispatch controller

Perform action and generate response
Magento\Framework\App\FrontController::dispatch(RequestInterface $request)

Here we can see that when router finds matches, action class (\Magento\Framework\App\ActionFactory) instance gets back. After that, front controller will call dispatch method on action class instance.

Validate and Match Cms Page and modify request

Magento\Cms\Controller\Router::match(\Magento\Framework\App\RequestInterface $request)

Dispatch request
Magento\Framework\App\FrontController::dispatch(RequestInterface $request)

For the main page, the following method will be called:

Flushing Output

Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Andrey

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *