在将 Joomla!2.5 仅后端组件改编为 Joomla!3.3 时,我遇到了数据编辑页面中的工具栏根本无法工作的问题。只声明了两个按钮:保存和取消;也不做任何事情。乍一看,问题既不在view.html.php文件上,也不在 tmpl/edit.php 上。这个组件已经在我们当前的 Joomla!2.5 网站中使用并且运行良好。
所有控制、模型和视图页面已经分别更新为JControllerLegacy、JModelLegacy和JViewLegacy(如果适用)。
视图.html.php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.viewlegacy');
class MrCarrosselNoticiasViewMrCarrosselNoticias extends JViewLegacy {
function display($tpl = null){
$form = $this->get('Form');
$item = $this->get('Item');
if (count($errors = $this->get('Errors'))){
JError::raiseError(500, implode('<br />', $errors));
return false;
}
$this->form = $form;
$this->item = $item;
$this->addToolBar();
parent::display($tpl);
}
protected function addToolBar(){
$input = JFactory::getApplication()->input;
$input->set('hidemainmenu', true);
$isNew = ($this->item->cod_destaque == 0);
JToolBarHelper::title($isNew ? "Novo Destaque" : "Editando Destaque");
JToolBarHelper::save('mrcarrosselnoticias.save');
JToolBarHelper::cancel('mrcarrosselnoticias.cancel', 'JTOOLBAR_CANCEL');
}
}