When debugging issues or doing development in Joomla!, it ishelpful to understand the basic Joomla! Execution Path.
Almost all requests to Joomla! start with the index.php filefound in the root of the Joomla! installation.
.../index.php
The following code is a security measure and defines a variableother pages use to make sure no one calls them directly.
// Set flag that this is a parent file define( '_JEXEC', 1 );
We then setup some other variables and include/require somefiles.
define('JPATH_BASE', dirname(__FILE__) ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
Finally, we do some work and get the Joomla! JApplication objectand call it's initialise method:
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
The online Joomla! API site is a great place to use as areference for looking up functions.
http://api.joomla.org/Joomla-Framework/JFactory.html#getApplication
http://api.joomla.org/Joomla-Framework/Application/JApplication.html#initialise
The API lists the files associated with these two classes whichcan be found here:
.../libraries/joomla/factory.php
.../libraries/joomla/application/application.php
For now, we won't worry about the specifics of the JApplicationinitialise method.
Next, we import the system plugins and trigger theonAfterInitialise method on them:
JPluginHelper::importPlugin('system'); // trigger the onAfterInitialise events JDEBUG ? $_PROFILER->mark('afterInitialise') : null; $mainframe->triggerEvent('onAfterInitialise');
The triggerEvent method is another one that we will seefrequently but won't explain every time.
Next, we call the route method:
$mainframe->route();
This is the description of what the route method does and is inthe application.php code:
function route()
Then we authorize that the user is allowed to see this menuitem:
// authorization $Itemid = JRequest::getInt( 'Itemid'); $mainframe->authorize($Itemid);
Once we know the user is allowed, we dispatch the request to theappropriate component:
$option = JRequest::getCmd('option'); $mainframe->dispatch($option);
The dispatch method is a very important call.
/index.php?option=com_content&view=article&id=39&Itemid=37
This is telling Joomla! to route the request to the com_contentcomponent.
Joomla! will then execute the following file for thecomponent:
.../components/com_content/content.php
For a component named com_somethingelse, Joomla! wouldexecute:
.../components/com_somethingelse/somethingelse.php
To see a full explanation of the execution path once inside acomponent, see the article
Finally, we render out the resulting response to the user:
$mainframe->render();
// trigger the onAfterRender events JDEBUG ? $_PROFILER->mark('afterRender') : null; $mainframe->triggerEvent('onAfterRender');
echo JResponse::toString($mainframe->getCfg('gzip'));
The render method is another very important call.
And that is it.
Other resources
PHP has wonderfully helpful functions called debug_backtrace anddebug_print_backtrace that will tell you the path PHP took to getto the code you are at:
http://php.net/manual/en/function.debug-backtrace.php
If you know you are getting to a certain place in the code butnot sure what path was taken, use these functions to help debug theissue.
PHP also has a wonderful function called print_r.