Joomla - Component: Creating Toolbars


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.

  1. create toolbar.hello.html.php file in the administrator/components/com_hello folder.
  2. 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();
    	}
    }
    ?>
    
  3. 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:


Create New Toolbar

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.

Add Toolbar


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming

Bookmark and Share Tag: joomla, cms, Joomla Component Category: PHP Framework Post : November 04th 2007 Read: 79,662

advertisements


blog comments powered by Disqus