Going through Joomla core structure

When any request is made in Joomla, it first passes through the main index.php file, located in the root folder. Similarly, when the backend is loaded, the request passes through the index file located in the administrator folder. I just want you to go through a quick overview of this file, so that you can get a valid understanding of how joomla works.

Please open index.php located in joomla root folder, in your favorite editor. There would be some php version check in the beginning but the most important code would be the below one.

define('_JEXEC', 1);

if (file_exists(__DIR__ . '/defines.php'))
	include_once __DIR__ . '/defines.php';

if (!defined('_JDEFINES'))
	define('JPATH_BASE', __DIR__);
	require_once JPATH_BASE . '/includes/defines.php';

require_once JPATH_BASE . '/includes/framework.php';

This is the bootstrap code for Joomla. It basically loads configuration file and makes a database connection. According to the singleton pattern, this connection is made only once in application instantiation and can be called from anywhere in the extension or template. This code brings all the libraries and chunks together and in place so that joomla application could be executed.

Next there comes the initialization of application so that code could be run on Joomla frontend.

JDEBUG ? $_PROFILER->setStart($startTime, $startMem)->mark('afterLoad') : null;

// Instantiate the application.
$app = JFactory::getApplication('site');

// Execute the application.

You can see here that getApplication function is being called. Here the site parameter is passed in to getApplication function on JFactory. This method actually loads the application in joomla according to the passed in variable and in this case, “site”. It runs from index.php file in the joomla root and loads frontend portion of the site, by calling $app->execute();

I am having a brief look at what is happening in this execute method i.e, through which steps Joomla will go through to load the complete frontend.

1) – Application is routed first:  Router takes the url that is passed in to Joomla and process it and decides which code should be picked and run.

2) – Dispatching the app:  Joomla gets the information about which component to run, from first step. In this second step, it runs the component and all the modules like login, search, menus etc. It gather the output of all these pieces, combines, and push them to memory.

3) – Rendering the app: After that the output from component and modules has been collected, it is loaded in the template in this step. Template has a placeholder for loading a single component at one time. and modules, It also has placeholders for modules, called module positions.

4) – After Rendering: Before sending the assembled data to browser, here at this point Joomla gives a last chance to make any modifications we want. Any changes made here will override the previous ones. After this step,the final output is sent to the browser.

Now move to Joomla core directory again and in the administrator folder, open up index.php file. On line 39, you can see

// Instantiate the application.
$app = JFactory::getApplication('administrator');

This time you will notice that we have passed “administrator” as parameter. What it will do is, it will load a completely separated backend from frontend.

You have to work with the “site” and “administrator” applications during the extension development which you are going to learn in this course. You can always restrict your code whether it should run on front or backend and we are going to discuss it in deep detail as we will progress further.

Next –> Some basic joomla settings before starting to develop extension.

Add a Comment

Your email address will not be published. Required fields are marked *


My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib

CEO: codingace.com

Request a Quote