Luyenkim.Net!

...where your idea grows!

 
  • Decrease font size
  • Default font size
  • Increase font size
Trang chủ arrow Công nghệ thông tin arrow Overview of Components - Sơ lược về Com
Overview of Components - Sơ lược về Com PDF Print E-mail
(0 votes)
Thứ sáu, 23 Tháng một 2007
Article Index
Overview of Components - Sơ lược về Com
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8

 

Creating the Administrator Interface

From Mambo Manual

There are a number of files required to support a component in the MOS Administrator. First you need to create a directory under the /administrator/components directory. You need to prefix this directory with com_. You also need four (possibly five) files; two to support the toolbar, two to support the component itself and maybe one other to define the table class.

Given that our component is called mrx_inout, the directory structure will look like this:

/administrator /components /com_mrx_inout admin.mrx_inout.php admin.mrx_inout.html.php toolbar.mrx_inout.php toolbar.mrx_inout.html.php /components /com_mrx_inout mrx_inout.class.php

Each of these files has a specific function:

admin.mrx_inout.php
This file is the event handler for the component.
admin.mrx_inout.html.php
This file provides the html output to support the event handler.
toolbar.mrx_inout.php
This file is the event handler that controls the display in the toolbar.
toolbar.mrx_inout.php
This file provides the html output to support the toolbar.
mrx_inout.class.php
This file provides the class definition for the database table class(es) for the component. A single file is used that is used by the front−end and the administrator (in circumstances where the component is not used in the frontend at all, like for News Feeds, this file can be place under the administrator tree with the rest of the component files).

It is the custom in Mambo to, wherever possible, separate the event handlers from the presentation layer. As much code crunching as is practical is done in the events handler before handing over to output the html. Hence, you will generally see 'pairs' of files to handle and then display events.

[edit]

The 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 MOS−ROX
6:
7: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License
8: * @version 4.5.1
9:
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.

1: <?php 
2: /* $Id: components.xml,v 1.6 2004/08/23 16:19:44 rcastley Exp $ */
3:/**
4: * In/Out Board Menubar Handler
5: * @package MOS−ROX7:
6: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License
7:
8: * @version 4.5.1
9:
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 initialise it, amongst other things, 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.




Related news items:
Newer news items:
Older news items:

 

Please install Flash and turn on Javascript.

Đăng nhập






Lost Password?
No account yet? Register

Liên kết website

vinaora.com
thietbidien.vn
Luyenkim.net
Trung tam ho tro giao vien
vnfolk.com
buaxua.vn

Thống kê

We have 7 guests online