Công nghệ thông tin
Overview of Components - Sơ lược về Com | Overview of Components - Sơ lược về Com |
|
|
|
| Thứ sáu, 23 Tháng một 2007 | ||||||||||
Page 5 of 8
Creating the Administrator InterfaceFrom Mambo ManualThere 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:
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 ToolbarYou 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 $ */ 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 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−> 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. Newer news items:
Older news items:
|
||||||||||
| Liên kết Webs |
| Why's luyenkim.net |
| Woman Calendar |
| Cà phê chiều thứ 7 |
| Từ điển LạcViệt Online |
| Kulkul's world |
| www.xahoihoctap.net |
| www.paper.edu.cn |
| Học tiếng Anh online |
| Danh bạ ĐT cố định |
| Online dictionary |
| Tivi Online |
| - - - - - - - |
| Tin thể thao |
| Dân trí |
| Tiền phong |
| Người lao động |
| - - - - - - - |