Note: This is just a skeleton
component, no error checking no validation, etc.
The overview: You create a zip
file that you can use to do an install using Mambo installer What is needed:
yourmcomponent.php, yourcomponent.xml and
admin.yourcomponent.php. Use these three files to create
com_yourcomponent.zip. (See
below for more optional files) What is yourcomponent.xml: This
is a file that the installer need to know some info regarding your
module and do the install What is yourcomponent.php: This
is a file where you put the logic of your component to be executed by
Mambo What is admin.yourcomponent.php:
This is a file where you put the logic of your component to be executed
by Mambo backend admin area
Here is a sample content would go in your yourcomponent.xml
Here is a content would go in your yourcomponent.php
Let say you want to get some data from your database and I just use the
content table as an example here. This is very simple version of a
component like a "hello world" type you can expand on this to utilize
the admin and toolbar in the back which I will cover below and to add
more customization to your component or add more data validation
routine. It is only limit to your imagination!
<? // beginning of component
// must have to protect from potential security risk
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not
allowed.' );
// declare your database
global $database;
// get the latest 5 articles
$qry="SELECT * FROM #__content WHERE published = '1' ORDER BY id DESC
LIMIT 5";
$database->setQuery($qry);
// get and load the records from the query
$rows = $database->loadObjectList();
// process each row, build and print the URL of the comment
foreach($rows as $row) {
echo "Article:<br />".$row-introtext."
".$row->fulltext."<br>";
}
// end of component
?>
Note: If you are going to have admin backend then you will need a few
more files: admin.yourcomponent.html.php, toolbar.yourcomponent.php,
toolbar.yourcomponent.html.php
Here is a content of yourcomponent.php. (Note: no admin backend
here but need to have a dummy file for component)
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not
allowed.' );
require_once( $mainframe->getPath( 'admin_html' ) );
// a dummy backend file for admin area
?>
Here some optional files that if you
have an admin area for your component
Here is a content of admin.yourcomponent.html.php.
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not
allowed.' );
class YOURCOMPONENT {
// some html related stuff used to show your admin backend
} //end class
?>
Here is a content of toolbar.yourcomponent.php.
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not
allowed.' );
require_once( $mainframe->getPath( 'toolbar_html' ) );
if ($task) {
// do something for the toolbar
}
?>
Here is a content of toolbar.yourcomponent.html.php.
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not
allowed.' );
class YOURCOMPONENT {
// do some html related stuff for your toolbar
}
?>