2

For which cases are these classes suitable? I've been trying to use both, but none of them works. The component skeleton was generated, and there are CRUD operations in the administrator's side. I tried using JToolbarHelper from this generated code, like this in 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');
    };
 }

But it doesn't even appear on the page.

Then I came across this tutorial http://docs.joomla.org/J3.x:Using_the_JToolBar_class_in_the_frontend and it kindof works, except I can't imagine implementing something like a list of entities with checkboxes and operations for each. And it's unclear for me how to handle form submissions using this approach, seems like it happens through JS, do I get it right?

So, please tell, what's the difference and why doesn't the first approach even make the toolbar appear?

LuckyLizard
  • 415
  • 3
  • 13
  • You cannot use JToolbar in the front end, if you look at the code you will see that it checks isAdmin(). – Elin Aug 22 '14 at 02:57
  • Why not? Simple JToolbar with a couple of buttons works, I followed the tutorial from official docs mentioned above. I just wonder whether I encounter any unsolvable problems in further development using this approach. – LuckyLizard Aug 22 '14 at 05:55
  • It's some historical thing going back to Joomla 1.0. I once tried to change it and it broke a lot of extensions. Someone needs to write a new package that will work in either place. – Elin Aug 22 '14 at 10:32

1 Answers1

1

I know this is a long time ago, but I was looking to achieve the same result and found the following to loads the toolbar on the page. Using the above code:

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');
    }
    $this->toolbar = JToolbar::getInstance(); // <<<---------- ADD THIS TO METHOD!
 }

Then in your view do this:

<?php echo $this->toolbar->render(); ?>

Hope this helps!!! enjoy.

Llewellyn
  • 388
  • 6
  • 19