请提供将Joomla 1.5组件更新为Joomla 2.5组件的步骤。
提前谢谢。
答案 0 :(得分:5)
在Adapting from 1.5 to 1.6和this DVLancer blog:
中可以学到很多东西全局变量$ mainframe和$ option
Joomla 1.5
global $mainframe, $option;
Joomla 2.5 替换为
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
或
$option = $this->option //If the code is in a controller class derived from JControllerForm
在模板中获取页面标题*
Joomla 1.5
global $mainframe;
$mainframe = &JFactory::getApplication();
$page_title = $mainframe->getPageTitle();
Joomla 2.5中的替换为
$app =& JFactory::getDocument();
$page_title = $app->getTitle();
模板路径
** Joomla 1.5
"templates/templatename/"
Joomla 2.5
$app= & JFactory::getApplication();
$template = $app->getTemplate();
或强>
"templates/".$this->template."/"
如何了解您是否在首页
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
}
访问错误变量
Joomla 1.5
$code = $this->error->code;
$message = $this->error->message;
在 Joomla 2.5 中,这些变量现在是私有的,必须通过getter方法访问以避免以下错误:
PHP cannot acess protected property error
$code = $this->error->getCode();
$message = $this->error->getMessage();