简体   繁体   中英

What does Mage::init do?

I'm trying to understand how exactly the Magento flow works after the request for a Magento-shop.

Therefore I'm stuck within the question: What does Mage::init() do and what the main difference between Mage::init() and Mage::run() is.

I hope there is someone who can help me.

Mage::init() :: initializes the application object with all variables and objects which are required to access Magento. Initialize application without request processing.

Mage::run() :: is the Frontend entry point which means it loads the configuration files, module configuration, load Database and handles request processing. Run application. Run process responsible for request processing and sending response.

As I found in the source code there are three option which can initialize Magento engine:

Mage::run(); As Veerendra wrote this will handle and render a Magento frontend site with lots of error handling. This call the frontend controller's dispatch method. Using this method the $this->_initModules(); call the resource setup and run database upgrade scripts where necessary. The Mage_Core_Model_Resource_Setup::applyAllUpdates(); will be called.

Mage::app(); As I seen this check if application already initialized and if not initializing the application and load areas. This method return the application object. This method not handle database update scripts and not call rendering methods so it is not use lot of CPU and RAM like run() . I think this method is useful for quick scripts to handling AJAX or any other API requests.

Mage::init(); As I seen it in the source code this method is between somewhere the two previous method. This method has some error handling (with redirecting and 404 page) but quiet similar to app() method because not rendering any output like run() method. This method has an extra $module parameter which can enable modules which are disabled at the admin site. Using this parameter the database upgrading scripts will called by $this->_initModules(); too like run() method. As I think this initialization is useful for API development.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM