【发布时间】:2014-08-21 09:31:38
【问题描述】:
这些类适合哪些情况?我一直在尝试同时使用这两种方法,但它们都不起作用。 组件骨架生成,管理员端有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 发生的,我理解对了吗?
那么,请告诉我,有什么区别,为什么第一种方法甚至没有让工具栏出现?
【问题讨论】:
-
你不能在前端使用JToolbar,如果你看代码你会发现它检查了isAdmin()。
-
为什么不呢?带有几个按钮的简单 JToolbar 可以工作,我按照上面提到的官方文档中的教程进行操作。我只是想知道使用这种方法在进一步开发中是否遇到任何无法解决的问题。
-
这是可以追溯到 Joomla 1.0 的一些历史事件。我曾经试图改变它,它破坏了很多扩展。有人需要编写一个可以在任何地方工作的新包。