Hal terpenting untuk suatu komponen di Joomla adalah memiliki file XML yang menentukan bagaimana komponen tersebut harus diintegrasikan ke dalam sang CMS. Sebagai contoh, anggaplah kita akan membuat sebuah komponen Joomla bernama “coba” yang berfungsi untuk menampilkan data user joomla.
Untuk itu file XML-nya dapat dibuat seperti ini:
file name coba.xml | |
"---> | <extension type="component" version="2.5.0" method="upgrade"> <name>coba!</name> <!-- The following elements are optional and free of formatting constraints --> <creationDate>Oktober 2013</creationDate> <author>syaifullah</author> <authorEmail>singkawangonline@gmail.com</authorEmail> <authorUrl>http://www.bni2strore.com</authorUrl> <copyright>Copyright Info</copyright> <license>License Info</license> <!-- The version string is recorded in the components table --> <version>0.0.1</version> <!-- The description is optional and defaults to the name --> <description>Menampilkan data user ...</description> <update> <!-- Runs on update; New in 2.5 --> <schemas> <schemapath type="mysql">sql/updates/mysql</schemapath> </schemas> </update> <!-- Site Main File Copy Section --> <!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /site/ in the package --> <files folder="site"> <filename>index.html</filename> <filename>coba.php</filename> <filename>localdata.php</filename> <filename>controller.php</filename> <folder>views</folder> </files> <administration> <!-- Administration Menu Section --> <menu>coba!</menu> <!-- Administration Main File Copy Section --> <!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /admin/ in the package --> <files folder="admin"> <!-- Admin Main File Copy Section --> <filename>index.html</filename> <filename>coba.php</filename> <filename>localdata.php</filename> <!-- SQL files section --> <folder>sql</folder> </files> </administration> </extension> |
Buatlah file coba.php (saya menggunakan dreamwever untuk membuat file coba.php) | |
<?php defined('_JEXEC') or die('Restricted access'); require_once('localdata.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_localdata, $localdata); $query_Recordset1 = "SELECT * FROM syi7k_users"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $localdata) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?><html> <table border="1" align="center"> <tr> <td>id</td> <td>name</td> <td>username</td> <td>email</td> <td>usertype</td> <td>sendEmail</td> <td>registerDate</td> <td>lastvisitDate</td> <td>activation</td> <td>params</td> </tr> <?php do { ?> <tr> <td><a href="/test.php?recordID=<?php echo $row_Recordset1['id']; ?>"> <?php echo $row_Recordset1['id']; ?> </a> </td> <td><?php echo $row_Recordset1['name']; ?> </td> <td><?php echo $row_Recordset1['username']; ?> </td> <td><?php echo $row_Recordset1['email']; ?> </td> <td><?php echo $row_Recordset1['usertype']; ?> </td> <td><?php echo $row_Recordset1['sendEmail']; ?> </td> <td><?php echo $row_Recordset1['registerDate']; ?> </td> <td><?php echo $row_Recordset1['lastvisitDate']; ?> </td> <td><?php echo $row_Recordset1['activation']; ?> </td> <td><?php echo $row_Recordset1['params']; ?> </td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <br> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="/<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="/<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="/<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="/<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?> </html> <?php mysql_free_result($Recordset1); ?> | |
selanjutnya melakukan penyesuaian pada baris paling atas yaitu : <?php defined('_JEXEC') or die('Restricted access'); require_once('localdata.php'); ?> | |
Membuat file koneksi berupa file localdata.php sebagai berikut : | |
<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_localdata = "localhost"; //sesuaikan dengan kondisi data masing $database_localdata = "joomdle"; //sesuaikan dengan kondisi data masing $username_localdata = "root";//sesuaikan dengan kondisi data masing $password_localdata = ""; $localdata = mysql_pconnect($hostname_localdata, $username_localdata, $password_localdata) or trigger_error(mysql_error(),E_USER_ERROR); ?> | |
Buat file index.html : | |
<html><body bgcolor="#FFFFFF"></body></html> | |
Buat file default.php : | |
<?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); ?> <h1><?php echo $this->msg; ?></h1> | |
Buat file controller.php | |
isinya blank | |
Buat file view.html.php | |
<?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); ?> <h1><?php echo $this->msg; ?></h1> | |
Buat file default.xml | |
<?xml version="1.0" encoding="utf-8"?> <metadata> <layout title="COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE"> <message> <![CDATA[COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC]]> </message> </layout> </metadata> | |
(silahkan sesuai dengan hasil yang anda inginkan) | |
Buat file 0.0.1.sql | |
isinya blank |
Skema data yang ditempatkan adalah sbb :
- coba.xml
- site/index.html
- site/coba.php
- site/localdata.php
- site/controller.php
- site/views/index.html
- site/views/coba/index.html
- site/views/coba/view.html.php
- site/views/coba/tmpl/index.html
- site/views/coba/tmpl/default.xml
- site/views/coba/tmpl/default.php
- admin/index.html
- admin/coba.php
- admin/sql/index.html
- admin/sql/updates/index.html
- admin/sql/updates/mysql/index.html
- admin/sql/updates/mysql/0.0.1.sql