Question

I am building a Joomla 2.5 component and have a bit of trouble getting the Delete button to function properly. Here is a sample code from the view.html.php file:

if ($canDo->get('core.delete'))
    {
        JToolBarHelper::deleteList('You Really Wanna Delete that', mycomponentname.delete, 'JTOOLBAR_DELETE');

When I select an item from a dropdown list and click to delete I get the following pop-up:

You Really Wanna Delete that

The problem with this is when I click the option to verify the deletion from the pop-up I am redirected to a 500 error message and the item is not deleted.

Now when I review the Joomla documentation here:

http://docs.joomla.org/JToolBarHelper

I see that JToolBarHelper is defined in administrator/includes/toolbar.php. So I went for a visit over to review the deleteList info there. I see the following code:

public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')
{
    $bar = JToolBar::getInstance('toolbar');
    // Add a delete button.
    if ($msg) {
        $bar->appendButton('Confirm', $msg, 'delete', $alt, $task, true);
    } else {
        $bar->appendButton('Standard', 'delete', $alt, $task, true);
    }
 }

So I have attempted to adjust my script by changing the second parameter $task = 'remove' to read as remove rather than mycomponentname.delete as follows:

JToolBarHelper::deleteList('You Really Wanna Delete that', 'remove', 'JTOOLBAR_DELETE');

This will eliminate the 500 error, but the item is not removed. What am I missing here? My guess is that it has something to do with improperly configuring the mycomponentname.delete function.


PS- I should add that the 500 error states:

Layout default not found

Was it helpful?

Solution

There is only one problem you have. You don't need to put the component name on to the button task. You need to put controller name instead of component name.

if ($canDo->get('core.delete'))
{
    JToolBarHelper::deleteList('You Really Wanna Delete that', 'controllerName.delete', 'JTOOLBAR_DELETE');
}

For example :

JToolBarHelper::deleteList('delete', 'hellos.delete','JTOOLBAR_DELETE');

Hope this helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top