Code changes to look for when upgrading extensions from Joomla 1.5 to Joomla 2.5. Feel free to send me any new tips to add to this article.
Global variables $mainframe and $option
Joomla 1.5
global $mainframe, $option;
in Joomla 2.5 replaced with
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
or
$option = $this->option //If the code is in a controller class derived from JControllerForm
Get page title within a template
Joomla 1.5
global $mainframe;
$mainframe = &JFactory::getApplication();
$page_title = $mainframe->getPageTitle();
in Joomla 2.5 replaced with
$app =& JFactory::getDocument();
$page_title = $app->getTitle();
Template Path
Joomla 1.5
"templates/templatename/"
Joomla 2.5
$app= & JFactory::getApplication();
$template = $app->getTemplate();
or
"templates/".$this->template."/"
How to find out if you are on the homepage
Joomla 1.5
if( JRequest::getVar('view') == "frontpage" ) {
// You are on the home page
} else {
// You are not
}
Joomla 2.5
$menu =& JSite::getMenu(); // get the menu
$active = $menu->getActive(); // get the current active menu
if ( $active->home == 1 ) { // check if this is the homepage
// You are on the home page
} else {
// You are not
}
Accessing Error Variables
Joomla 1.5
$code = $this->error->code;
$message = $this->error->message;
Joomla 2.5
In Joomla 2.5 those variable are now private and have to be accessed via getter methods to avoid the following error:
PHP cannot acess protected property error
$code = $this->error->getCode();
$message = $this->error->getMessage();
Replaced Module
Some modules were replaced. For example mod_latestnews in Joomla 1.5 was replaced by mod_articles_latest in Joomla 2.5, so you'll need to update template overrides
Article template override
If you have a custom article template override (/templates/YOURTEMPLATE/html/com_content/article) then you'll need to replace all occurrences of $this->article with $this->item. show_page_title was also needs to be replaced by show_page_heading
Joomla 1.5
$this->params->get('show_page_title', 1)
$this->article...
Joomla 2.5
$this->params->get('show_page_heading')
$this->item...
Related links
Last Updated on Sunday, 07 April 2013 21:43
Comments
RSS feed for comments to this post