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 the Joomla root folder, in your favourite editor. There would be some PHP version checks 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 a 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 of the libraries and chunks together and into place, allowing the Joomla application to run.

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 the getApplication function is being called. Here, the site parameter is passed in to the getApplication function on JFactory. This method actually loads the application in Joomla according to the passed-in variable, in this case, “site.” It runs from the index.php file in the Joomla root and loads the 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 to load the complete frontend.

1) An application is routed first: The Router process the URL that is passed to Joomla, determining which code should be selected and executed.

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

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

4) After Rendering: Before sending the assembled data to the browser, at this point, Joomla gives us one 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.

Return to the Joomla core directory and open the index.php file in the administrator folder.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 that you are going to learn in this course. You can always restrict your code to whether it should run on the front or backend, and we are going to discuss it in deep detail as we 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

PHP Code Snippets Powered By : XYZScripts.com