这些类适合哪些情况?我一直在尝试同时使用这两种方法,但它们都不起作用。组件骨架生成,管理员端有CRUD操作。我尝试从这个生成的代码中使用 JToolbarHelper,就像在 mycomponent/view.html.php 中一样:
// Overwriting JView display method
function display($tpl = null)
{
// Include helper submenu
InvoiceHelper::addSubmenu('invoice');
// Assign data to the view
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
// Check for errors.
if (count($errors = $this->get('Errors'))){
JError::raiseError(500, implode('<br />', $errors));
return false;
};
// Set the toolbar
$this->addToolBar();
// Show sidebar
$this->sidebar = JHtmlSidebar::render();
// Display the view
parent::display($tpl);
}
protected function addToolBar()
{
JLoader::register('JToolbarHelper', JPATH_ADMINISTRATOR.'/includes/toolbar.php');
$canDo = InvoiceHelper::getActions();
JToolBarHelper::title(JText::_('Invoice Manager'), 'invoice');
if($canDo->get('core.create')){
JToolBarHelper::addNew('invoic.add', 'JTOOLBAR_NEW');
};
if($canDo->get('core.edit')){
JToolBarHelper::editList('invoic.edit', 'JTOOLBAR_EDIT');
};
if($canDo->get('core.delete')){
JToolBarHelper::deleteList('', 'invoice.delete', 'JTOOLBAR_DELETE');
};
}
但它甚至没有出现在页面上。
然后我遇到了这个教程http://docs.joomla.org/J3.x:Using_the_JToolBar_class_in_the_frontend并且它有点工作,除了我无法想象实现一个带有复选框和操作的实体列表之类的东西。我不清楚如何使用这种方法处理表单提交,似乎是通过 JS 发生的,我说得对吗?
那么,请告诉,有什么区别,为什么第一种方法甚至没有使工具栏出现?