You Are Here: Home » Magento tutorials » Magento Tutorials: Front Controller (Part 2)

Magento Tutorials: Front Controller (Part 2)

The Front Controller has an array of “routers” that it uses to decide which module the URL should trigger so Front Controller plays a very crucial role in Magento. And do you know how to locate Front Controller class, or events that Front Controller fires and Front Controller’s responsibilities? If you are interested in these issues, please follow my article.
I. Locate Front Controller class

- The position of the directory: app/code/core/Mage/Core/Controller/Varien/Front.php

- Receive all requests from browser and return HTML code.

- Front controller uses routes of the system to define the controller and the action that are called.

- Example: routers in the file config.xml of the Customer module.

- Routers can receive 3 values for the bar including:

  • Standard (class Mage_Core_Controller_Varien_Router_Standard)
  • Admin (class Mage_Core_Controller_Varien_Router_Admin)
  • Default (class Mage_Core_Controller_Varien_Router_Default

II -List all events that Front Controller fires
– controller_front_init_before (app/code/core/Mage/Core/Controller/Varien/Front.php)

  • ‘front’ => Mage_Core_Controller_Varien_Front

- controller_front_init_routers (app/code/core/Mage/Core/Controller/Varien/Front.php)

  • ‘front’ => Mage_Core_Controller_Varien_Front

- controller_front_send_response_before (app/code/core/Mage/Core/Controller/Varien/Front.php)

  • ‘front’ => Mage_Core_Controller_Varien_Front

- controller_front_send_response_after (app/code/core/Mage/Core/Controller/Varien/Front.php)

  • ‘front’ => Mage_Core_Controller_Varien_Front

III. Explain Front Controller’s responsibilities
– Directly receive the request from browser.

  • All requests call the function Mage_Core_Controller_Varien_Front::dispatch()

- URL rewriting process.
– Load the module and action controller corresponding with the requests through routers to process the requirements which are sent from clients.

  • Collect routers: admin, standard, default.
  • Use the function match() of routers to define the module and controller that are requested.
  • Call the function dispatch() of the controller requested.
  • Call the action requested.

- Return HTML for browser

  • Call the function sendResponse() of Mage_Core_Model_Response_Http (extend from Zend_Controller_Response_Abstract).
  • Call the function sendHeaders() – use the header() function of PHP.
  • Call the function outputBody() to show the whole content of the body part:

echo implode('', $this->_body);

Question: Where is the value of $this > _body receive from?
Answer: The variable $_body is an array() and Action controller added value to this variable.
For example: When you call $this > renderLayout() in Action controller:

$output = $this->getLayout()->getOutput();
Mage::getSingleton('core/translate_inline')
->processResponseBody($output);
$this->getResponse()->appendBody($output);

If you have any problems, please don’t hesitate to contact me or leave a comment below.

Source:magestore.com

About The Author

avatar

Magento Tutorial will provide you information and knowledge about Magento. Morever, members in Mageto community here can help one another to solve any troubles about Magento.

Number of Entries : 244

Comments (2)

Leave a Comment

Scroll to top
" "