Access Keys:
Skip to content (Access Key - 0)
Home (Access Key - 1)
All spaces... (Access Key - 3)
Log in (Access Key - 5)
Sign up (Access Key - 6)
Development

Mambo Manual is part of the documentation project for the Mambo open source content management system

Toggle Sidebar

The Component Toolbar


 Component Toolbar

You need two files to control the display of the toolbar in the MOS Administrator. One file is the event handler (toolbar..php) and one controls the html output (toolbar..html.php) . This segregation of business logic and display is common throughout most of the Mambo codebase.

Let's have a look at the file that handles the html output first. Create a file called toolbar.mrx_inout.html.php in the /administrator/components/com_mrx_inoutdirectory.

Copy the following code into it and then we'll dissect what's happening.

 1: <?php /* $Id $ */

2:

3: /**

4: * In/Out Board Menubar HTML Writer

5: * @package MOSROX

7: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License

8: * @version 4.5.1

10: */

11:

12: // ensure this file is being included by a parent file

13: defined( '_VALID_MOS' ) or
 die( 'Direct Access to this location is not allowed.' );

14:

15: class TOOLBAR_mrx_inout {

16: /**

17: * Draws the menu to add or edit an item

18: */

19: function _EDIT() {

20: mosMenuBar::startTable();

21: mosMenuBar::save();

22: mosMenuBar::cancel();

23: mosMenuBar::spacer();

24: mosMenuBar::endTable();

25: }

26:

27: function _DEFAULT() {

28: mosMenuBar::startTable();

29: mosMenuBar::addNew();

30: mosMenuBar::editList();
31: mosMenuBar::deleteList();

32: mosMenuBar::spacer();

33: mosMenuBar::endTable();

34: }

35: }?>

Line 13:

This is an essential part of the MOS security system that prevents a user from directly executing this script, for malicious purposes or otherwise.

Line 15?35:

These lines define a class to handle the output of the toolbar. The class has two methods, one to display the toolbar for editing a record (_EDIT), and another to display for any other task (_DEFAULT). Each of these methods are an assembly of API methods to create the toolbar. These methods are part of the mosMenuBar class. Because these are what might be called 'helper' or 'utility' methods of the class that don't interact with the properties of the class, we don't have to instantiate (this is, create) the class to use the methods. We simply call them via the class_name::method_name() syntax.

The _EDIT method will display a Save and a Cancel button. The startTable and endTable methods merely provide the html to open (<table><tr>) and close (</tr></table>) the table wrapping the toolbar. The spacer method provide a wide empty cell to keep the toolbar buttons bunched up of the left.

The _DEFAULT method will display a New, Edit and Delete button.

Now we need to build the event handler to display the correct toolbar. Create a file called toolbar.mrx_inout.php in the /administrator/components/com_mrx_inout directory.

Copy the following code into it and then we'll again dissect what's happening.

 <?php /* $Id: components.xml,v 1.6 2004/08/23 16:19:44 rcastley Exp $ */

2:

3: /**

4: * In/Out Board Menubar Handler

5: * @package MOS?ROX

7: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License

8: * @version 4.5.1

10: */

11:

12: // ensure this file is being included by a parent file

13: defined( '_VALID_MOS' ) or
 die( 'Direct Access to this location is not allowed.' );

14:

15: require_once( $mainframe?>getPath( 'toolbar_html' ) );

16:

17: switch ( $task ) {

18:

19: case "new":

20: case "edit":

21: TOOLBAR_mrx_inout::_EDIT();

22: break;

23:

24: default:

25: TOOLBAR_mrx_inout::_DEFAULT();

26: break;

27: }

28: ?>

Line 15:

This line pulls in the previous file (toolbar.mrx_inout.html.php). The variable $mainframe is a class of utility methods. When it is initialised, amongst other things, it checks for the existence of toolbar and class files. These could be in a number of locations as the method supports some legacy styles of coding. In our case, the getPath method would return: /administrator/components/com_mrx_inout/toolbar.mrx_inout.html.php

The argument passed to the method is shorthand for asking the function to retrieve the path for the file that handling the html output for the toolbar.

You could have just as easily written:

 15: require_once( $mainframe?>getPath( '/administrator/components/com_mrx_inout/toolbar.mrx_inout.html.php ' ) );

Line 17:

Starts the switch block for the task.

Line 19-21:

If the task is either 'new' or 'edit' then we call the function to write the html for EDIT_MENU. Remember in the toolbar.mrx_inout.html.phpfile we created the menu_mrx_inout class with two methods. Again, as neither of these two functions interact with the properties of the class we can call them directly using the class_name::method_name() syntax. For reference, the double colon :: is called the scope indirection operator.

Line 24-25:

For any other task we call the function to write the _DEFAULT toolbar.

Next Page: Database Class Handlers

Toggle Sidebar
Space Navigation
Added by Lynne Pope on 28 Dec, 2007 12:00, last edited by Lynne Pope on 03 Jan, 2008 10:37

Adaptavist Theme Builder Powered by Atlassian Confluence
Free theme builder license