You see, all the core components implements toolbar with similar button for saving, deleting, editing, and publishing items. You can use these buttons in your component too.
- create toolbar.hello.html.php file in the administrator/components/com_hello folder.
- Write following code at toolbar.hello.html.php:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class TOOLBAR_hello {
function _NEW() {
JToolBarHelper::save();
JToolBarHelper::apply();
JToolBarHelper::cancel();
}
function _DEFAULT() {
JToolBarHelper::title( JText::_( 'Hello World Manager' ), 'generic.png' );
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();
}
}
?>
- The toolbar are now defined, but you need to add some code that will decide which one to display. In the back end, Joomla! automatically loads the file beginning with component name and ending in .hello.php in the upper right-hand portion of the screen. Create toolbar.hello.php and write following code into that file:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JApplicationHelper::getPath( 'toolbar_html' ) );
switch ( $task )
{
case 'add' :
TOOLBAR_hello::_NEW();
break;
default:
TOOLBAR_hello::_DEFAULT();
break;
}
?>
Refresh the browser in the back end and go to Hello World under Components. You should see the following screen:
To see the other toolbar, add &task=add to the end of the URL in your browser (ex. http://localhost/joomla/administrator/index.php?option=com_hello&task=add), then load it.