Magento Tutorials: Front Controller (Part 2)
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

website
All material copied from yet another source
Eric
Hi, at magentotutorial, we write and also collect magento tutorials over the internet. We just want to create a good source of magento tutorials for everyone