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 Kinh nghiệm-thủ thuật 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

Component Presentation Layer

From Mambo Manual

Here is where the first half of the serious work starts. We need to create a presentation layer to display the html for different events that are going to be triggered by our component. The presentation layer is a file that builds up as we develop additional functionality.

Let's start small. Let's examine what we need just to display a list of users allocated to an in/out board.

Create a file called admin.mrx_inout.html.php in the /administrator/components/com_mrx_inout directory. Copy the following code into it and then we'll dissect what's happening. Please don't worry about the fact that the line numbers are not sequential. There are just for reference purposes.

1: <?php /* $Id $ */
2:
3: /**
4: * In/Out Board Main HTML Writer
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: class HTML_mrx_inout {
16: /**
17: * Display the list of users
18: */
19: function listUsers( &$rows, &$lists, &$pageNav, $option ) {
20: global $my;21: ?>
22: <form action="index2.php" method="post" name="adminForm">
23: <table class="adminheading">
24: <tr>
25: <th>MRX In/Out Board − User List</th>
26: <td nowrap="true">Display #</td>
27: <td> <?php echo $pageNav−>getLimitBox(); ?> </td>
28: <td width="right"> <?php echo $lists['catid'];?> </td>
29: </tr>30: </table>
31:
32: <table class="adminlist">
33: <tr>34: <th width="20">#</th>
35: <th width="20"><input type="checkbox" name="toggle" value=""
onclick="checkAll(<?php echo count( $rows ); ?>);" /></th>
36: <th class="title" width="50%">Users</th>
37: <th width="15%" align="left">Category</th>
38: <th colspan="2">Reorder</th>
39: </tr>40: <?php
41: $k = 0;
42: for ($i=0, $n=count( $rows ); $i < $n; $i++) {
43: $row = &$rows[$i];
44: ?>
45: <tr class="<?php echo "row$k"; ?>">
46: <td width="20" align="center"><?php echo $i+$pageNav−>limitstart+1;?></td>
47: <td width="20">
48: <?php if ($row−>checked_out && $row−>checked_out != $my−>id) { ?>
49:
50: <?php } else { ?>
51: <input type="checkbox" id="cb<?php echo $i;?>"
name="cid[]"value="<?php echo $row−>id; ?>" onclick="isChecked(this.checked);" />
52: <?php } ?>
53: </td>
54: <td width="50%"><a href="http://localhost/joomlabr/#edit"
onclick="returnlistItemTask('cb<?php echo $i;?>','edit')">
<?php echo $row−>name; ?> </a></td>
55: <td width="50%"><?php echo $row−>catname;?></td>
56: <td width="20">57: <?php if ($i > 0 || ($i+$pageNav−>limitstart > 0)) { ?>
58: <a href="http://localhost/joomlabr/#reorder"
onclick="return listItemTask('cb<?php echo$i;?>','orderup')">
59: <img src="images/uparrow.png" width="16" height="16"border="0" alt="Move Up">
60: </a>
61: <?php } ?>
62: </td>
63: <td width="20">
64: <?php if ($i < $n−1 || $i+$pageNav−>limitstart < $pageNav−>total−1) {?>
65: <a href="http://localhost/joomlabr/#reorder"
onclick="return listItemTask('cb<?php echo$i;?>','orderdown')">
66: <img src="images/downarrow.png" width="16" height="16"border="0" alt="Move Down">
67: </a>
68: <?php } ?>
69: </td>
70: </tr>
71: <?php
72: $k = 1 − $k;
73: }
74: ?>
75: <tr>
76: <th align="center" colspan="10"> <?php echo $pageNav−>writePagesLinks(); ?></th>
77: </tr>
78: <tr>
79: <td align="center" colspan="10"> <?php echo $pageNav−>writePagesCounter(); ?></td>
80: </tr>
81: </table>
82:
83: <input type="hidden" name="option" value="<?php echo $option;?>" />
84: <input type="hidden" name="task" value="" />
85: <input type="hidden" name="boxchecked" value="0" />
86: </form>
87: <?php
88: }
143: }
144:
145: ?>

Looks confusing? Well, it's not too hard. Let's walk you through.

Line 15:

We wrap the presentation methods in a class. You can call it what you like but the customary convention is HTML_component_name.

Line 19:

This is the first method we will build into the presentation layer. We've called it listUsers. We pass four arguments to the function. &$rows will be a array of objects that equate to rows in our database table.

Notice the ampersand. This means we are passing this array by its reference. If we didn't, then a copy of the array would be passed to the method. If this array took up, for example, 100kb of memory, we would have just added another 100kb to the memory stack. Passing by reference means we work on the original array and is far more memory efficient. &$catlist will be a string of preformatted html for a select list for categories. &$pageNav is an object that helps us with pagination of the list. $option is the option argument passed via the URL or a submitted form. We could hardcode it but, again, it is customary to pass the option around. This makes it easy to cut−and−paste code from other components already built without changing a lot of standard code.

Lines 22 & 86:

The entire list is wrapped in a HTML form named "adminForm". The toolbar buttons expect this form to exist.

Line 23−30:

This is a table that displays a heading, the display limit and a drop−down list to filter by category. Line 27:

The pageNavigation class has a method called "writeLimitBox". This method handles the display of the drop−down list for the number of records to display on a page.

Line 28:

We will have already assembled the HTML for the category drop−down list using a number of utility functions (we'll come to that shortly). All you have to do is output the variable.

Line 32−39:

We have started another table to display the list of users. This code block defines the column headings. Line 35 contains a special checkbox that is used to select or deselect all of the items shown in the list.




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

Sửa ĐTDD
thietbidien.vn
Thư viện cộng đồng
onbai.com
Trung tam ho tro giao vien
Luyenkim.net

Thống kê

We have 51 guests and 1 member online