Basic Reminder of how to create Joomla Component
- June 22nd, 2008
- Posted in Joomla
- Write comment
Front End : Lets assume our component is called gold
1- Create a sub folder for the component folder call it com_gold
2- Create a file called gold.php inside of it (Known as Entry Point)
<?php
defined(‘_JEXEC’) or die(‘Restricted access’);require_once( JPATH_COMPONENT.DS.‘controller.php’ );
if($controller = JRequest::getWord(‘controller’)) {
$path = JPATH_COMPONENT.DS.‘controllers’.DS.$controller.‘.php’;
if (file_exists($path)) {
require_once $path;
} else {
$controller = ”;
}
}
$classname = ‘goldController’.$controller;
$controller = new $classname( );
$controller->execute( JRequest::getVar( ‘task’ ) );
$controller->redirect();
?>
?>
Back End :
1- Create a sub folder for the administrator/components folder call it com_gold
2- Create a file called admin.gold.php inside of it
Now you can Access the Component
http://localhost/joomla/index.php?option=com_gold
——————
Adding :
1- Controller to Front End : The controller is responsible for responding to user actions
create a file called controller.php inside com_gold
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.application.component.controller'); class GoldController extends JController { function display() { parent::display(); } } ?>
2- View to Front End : part of the component that is used to render the data from the model in a manner that is suitable for interaction
create views/gold/gold.html.php inside com_gold
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); class GoldView extends JView { function display($tpl = null) { $sentence = "Gold Component"; $this->assignRef( 'sentence', $sentence ); parent::display($tpl); } } ?>
2- Template to Front End :
create views/gold/tmpl/default.php inside com_gold
<?php // no direct access defined('_JEXEC') or die('Restricted access'); ?> <h1><?php echo $this->greeting; ?></h1>
No comments yet.