When debugging issues or doing development in Joomla!, it ishelpful to understand the basic Joomla! Execution Path.<wbr>The execution path is the list of function callsthat are made during each page request. <wbr>While thecalls will change from request
to request (depending on querystring parameters, cookies, session information, etc), the basicpath is the same each time. <wbr>We will cover thebasics and provide information to help developers find informationfor their<wbr>specific<wbr>situation.</wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
Almost all requests to Joomla! start with the index.php filefound in the root of the Joomla! installation.<wbr>Administrator requests go to the<strong>.../administrator/index.php</strong> file, but are similarto front-end calls. <wbr>There are also some
caseswhere certain pages can be called directly, but in most cases,index.php is the starting point.</wbr></wbr>
<wbr></wbr>
.../index.php
The following code is a security measure and defines a variableother pages use to make sure no one calls them directly.<wbr>All other php files that should not be calleddirectly in Joomla! should include a check for this variable at thetop of the file:</wbr>
// Set flag that this is a parent file
define( '_JEXEC', 1 );
We then setup some other variables and include/require somefiles. <wbr>The PROFILER code is used if you haveDebug System turned On in the Global Configuration and is used toprint out debug information at the bottom of the page.<wbr>We will see more calls
like this throughout thefile and will ignore them:</wbr></wbr>
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. <wbr>ThegetApplication function and initialise method can be foundhere:</wbr>
http://api.joomla.org/Joomla-Framework/JFactory.html#getApplication
http://api.joomla.org/Joomla-Framework/Application/JApplication.html#initialise
<wbr></wbr>
The API lists the files associated with these two classes whichcan be found here:
.../libraries/joomla/factory.php
.../libraries/joomla/application/application.php
<wbr></wbr>
For now, we won't worry about the specifics of the JApplicationinitialise method. <wbr>If you want to open the fileand look at the code to see what it does, that is the best way tolearn. <wbr>For now, just know that it initialises theapplication. ;-)</wbr></wbr>
<wbr></wbr>
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. <wbr>Thiscall tells Joomla! to go through each enabled plugin of a certaintype and call the event on it. <wbr>In this case, thisis calling the System plugin
onAfterInitialise event.</wbr></wbr>
<wbr></wbr>
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()
<wbr></wbr>
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.<wbr>This is the entry point into the component thatis being requested. <wbr>Every request to Joomla! endsup going to a specific component and follows a similar path.<wbr>For this example, let's assume we are
requestingthe following URL:</wbr></wbr></wbr>
/index.php?option=com_content&view=article&id=39&Itemid=37
<wbr></wbr>
This is telling Joomla! to route the request to the com_contentcomponent. <wbr>The Itemid query string variable tellsJoomla! which menu item this request is for (as used above whenauthorizing). <wbr>Most of the other query stringvariables are used in the
component, but a lot of them (view,controller, task, etc) are used across most components.</wbr></wbr>
<wbr></wbr>
Joomla! will then execute the following file for thecomponent:
.../components/com_content/content.php
For a component named com_somethingelse, Joomla! wouldexecute:
<wbr></wbr>
.../components/com_somethingelse/somethingelse.php
<wbr></wbr>
<wbr></wbr>
To see a full explanation of the execution path once inside acomponent, see the article<wbr><a href="http://www.cmsmarket.com/resources/dev-corner/112-joomla-component-execution-path-walkthrough" target="_blank">Joomla! Component Execution PathWalkthrough</a>.</wbr>
<wbr></wbr>
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.<wbr>This call will tell the JDocument object torender itself and will result in the template and modules beingrendered. <wbr>This topic will also be covered inanother future article that will eventually
be linked to fromhere.</wbr></wbr>
<wbr></wbr>
And that is it. <wbr>Not terribly complicated andeasy to follow.</wbr>
<wbr></wbr>
<wbr></wbr>
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.
<wbr></wbr>
PHP also has a wonderful function called print_r.<wbr>While the print function can be used to print astring or number, it can't be used to easily print out an object.<wbr>That is where print_r can be helpful:</wbr></wbr>
http://php.net/manual/en/function.print-r.php
相关推荐
Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发,可运行在Linux、Windows、MacOSX、Solaris等各种平台上。
Joomla3.2.0稳定版安装程序,学习Joomla必备之Joomla系统安装!
joomla中文模板wm-09 中文模板,版面风格简单清新
joomla1.6模板 jm-school
joomla1.6模板 jm-creative
joomla1.6模板 jm-rabbit
joomla1.6模板 jm-rzdesign
joomla1.6模板 jotempre-template_three_v1.2
joomla1.6模板 jm-experts2
Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发,可运行在Linux、Windows、MacOSX、Solaris等各种平台上。Joomla!除了具有新闻/文章管理,文档/图片...
Joomla_2.5.1-Stable-Full_Package 最新版joomla CMS系统
可用于Joomla实现真正的静态页面转化 可支持Joomla1.5-Joomla1.7,在Joomla2.5上使用正常
PDF-Joomla1.5TemplateDesign-英文版.rar
joomla附件插件attachments-3.2.3.zip,内容管理系统
Building.Websites.with.Joomla1.5 & joomla 1.5建站宝典 第一单元:术语,概念,和审议 joomla 1.5安装方法 第三单元 前台内容 第三单元 前台内容? 第三单元 后台 Joomla 管理配置! 帮助菜单 网站菜单 用户管理器...
Joomla 播放视频的插件all videos 支持版本:1.5-2.5
BitNami是一个开源项目,该项目产生的开源软件包括安装 Web应用程序和解决方案堆栈,以及虚拟设备。bitnami主办Bitrock公司成立于2003年在西班牙塞维利亚,由丹尼尔·洛佩兹Ridruejo。bitnami栈用于安装在Linux,...
类似于all videos的插件,可自己添加新的可支持的网站的视频 用法可参考http://www.cnblogs.com/sun_moon_earth/archive/2009/08/12/1544069.html(非本人创作的文章)
可用于新闻展示,幻灯片 版本:支持Joomla1.5 Joomla1.7,在Joomla2.5上也可以很好的使用
sc_joomla-plg_jwsigpro-v2.0sc_joomla-plg_jwsigpro-v2.0