We have finished Magento Basics with 9 articles which guide you about fundamentals, configuration XML, and multi-language… in Magento. Today, I will start the next step of Magento Certificate Preparation. You will be introduced the first topic – Application initialization consisting of two parts:

  1. Describe the steps for the application initialization.
  2. Change a website from within index.php.

I. Describe the steps for application initialization

  • Run the file index.php
  • Include Mage.php

● If not existing => redirect to the downloader of  magento

● If existing a file Mage.php => Conduct the command: Mage::run($mageRunCode, $mageRunType);

  • App::run($mageRunCode, $mageRunType)

● Load configuration files in app/etc/modules

● Load configuration files in the module (app/code/core/Mage/Customer/etc/config.xml)

● Update/create version of modules in core_resource

● Update/create database of modules

  • Mage_Core_Controller_Varien_Front::dispatch()

● Use routers to define the controller and action requested

● Call dispatch() of the controller that is requested

● Call action of the controller that is requested

● Return HTML code for the browser

II. Change a website from within index.php

Change the website and uses of index.php by the following steps:

Step 1: Create Website

  • Generate catalog, root category (Catalog > Manage Categories)
  • Manage store, create website, store and store view (System > Manage Stores)
  • Configure Base Url for the website which has been created (System > Configuration tab Web)

Step 2: Insert the code below into index.php before the command: Mage::run($mageRunCode, $mageRunType);

switch($_SERVER['HTTP_HOST']) {
	case 'name_domain_1':
	case 'name_domain_n':
		$mageRunCode = 'website_code';
		$mageRunType = 'website';
	break;
}

Hope this post will give you great helps! 🙂

Author

Alex is the CTO & Co-founder of Magestore which has been providing retail solutions for Magento merchants since 2009. He started as a Magento developer just one year after the release of the first version of Magento. With over 10 years experience of working with Magento and clients all over the world, he gained great knowledge on e-commerce development, order management systems, inventory control & retail POS.

2 Comments

  1. Toon Van Dooren Reply

    Just a remark, it’s better to redirect to certain websites/stores from your vhost file. You can do this by using

    SetEnv MAGE_RUN_CODE “base” # put here your website or store code
    SetEnv MAGE_RUN_TYPE “website” # put here ‘website’ or ‘store’

    This way you can keep your settings after upgrading your version. Cheers!

Write A Comment