J3.x

Difference between revisions of "Developing an MVC Component/Adding backend actions"

From Joomla! Documentation

< J3.x:Developing an MVC Component
(22 intermediate revisions by 5 users not shown)
Line 7: Line 7:
  
 
== Adding a toolbar ==
 
== Adding a toolbar ==
In Joomla, the administrator interacts generally with components through the use of a toolbar. In the file ''admin/views/helloworlds/view.html.php'' put this content. It will create a basic toolbar and a title for the component.
+
In Joomla, the administrator interacts generally with components through the use of a toolbar. In the file ''''admin/views/helloworlds/view.html.php'''' put this content. It will create a basic toolbar and a title for the component.
  
 
The arguments used in, for example, JToolBarHelper::addNew is used to set a controller instance which will be used after button is clicked. Further details below in the [[#Adding_specific_controllers | adding specific controllers]] section.
 
The arguments used in, for example, JToolBarHelper::addNew is used to set a controller instance which will be used after button is clicked. Further details below in the [[#Adding_specific_controllers | adding specific controllers]] section.
 
    
 
    
 
<span id ="admin/views/helloworlds/view.html.php">
 
<span id ="admin/views/helloworlds/view.html.php">
''admin/views/helloworlds/view.html.php''
+
'''''admin/views/helloworlds/view.html.php'''''
<source lang="php">
+
<source lang="php" highlight="41,42,55-61">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
 
jimport('joomla.application.component.view');
 
  
 
/**
 
/**
 
  * HelloWorlds View
 
  * HelloWorlds View
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldViewHelloWorlds extends JViewLegacy
 
class HelloWorldViewHelloWorlds extends JViewLegacy
 
{
 
{
 
/**
 
/**
* HelloWorlds view display method
+
* Display the Hello World view
 +
*
 
* @param  string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 
* @param  string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 
*
 
*
* @return  mixed  A string if successful, otherwise a JError object.
+
* @return  void
 
*/
 
*/
function display($tpl = null)  
+
function display($tpl = null)
 
{
 
{
 
// Get data from the model
 
// Get data from the model
$items = $this->get('Items');
+
$this->items = $this->get('Items');
$pagination = $this->get('Pagination');
+
$this->pagination = $this->get('Pagination');
  
 
// Check for errors.
 
// Check for errors.
if (count($errors = $this->get('Errors')))  
+
if (count($errors = $this->get('Errors')))
 
{
 
{
 
JError::raiseError(500, implode('<br />', $errors));
 
JError::raiseError(500, implode('<br />', $errors));
 +
 
return false;
 
return false;
 
}
 
}
// Assign data to the view
 
$this->items = $items;
 
$this->pagination = $pagination;
 
  
 
// Set the toolbar
 
// Set the toolbar
Line 56: Line 62:
  
 
/**
 
/**
* Setting the toolbar
+
* Add the page title and toolbar.
 +
*
 +
* @return  void
 +
*
 +
* @since  1.6
 
*/
 
*/
protected function addToolBar()  
+
protected function addToolBar()
 
{
 
{
 
JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'));
 
JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'));
 +
JToolBarHelper::addNew('helloworld.add');
 +
JToolBarHelper::editList('helloworld.edit');
 
JToolBarHelper::deleteList('', 'helloworlds.delete');
 
JToolBarHelper::deleteList('', 'helloworlds.delete');
JToolBarHelper::editList('helloworld.edit');
 
JToolBarHelper::addNew('helloworld.add');
 
 
}
 
}
 
}
 
}
Line 74: Line 84:
  
 
<span id="admin/views/helloworlds/tmpl/default.php">
 
<span id="admin/views/helloworlds/tmpl/default.php">
''admin/views/helloworlds/tmpl/default.php''
+
'''''admin/views/helloworlds/tmpl/default.php'''''
<source lang="php">
+
<source lang="php" highlight="42,50,65,66,67">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted Access');
 
defined('_JEXEC') or die('Restricted Access');
// load tooltip behavior
 
JHtml::_('behavior.tooltip');
 
 
?>
 
?>
<form action="<?php echo JRoute::_('index.php?option=com_helloworld'); ?>" method="post" name="adminForm" id="adminForm">
+
<form action="index.php?option=com_helloworld&view=helloworlds" method="post" id="adminForm" name="adminForm">
<table class="adminlist">
+
<table class="table table-striped table-hover">
<thead><?php echo $this->loadTemplate('head');?></thead>
+
<thead>
<tfoot><?php echo $this->loadTemplate('foot');?></tfoot>
+
<tr>
<tbody><?php echo $this->loadTemplate('body');?></tbody>
+
<th width="1%"><?php echo JText::_('COM_HELLOWORLD_NUM'); ?></th>
 +
<th width="2%">
 +
<?php echo JHtml::_('grid.checkall'); ?>
 +
</th>
 +
<th width="90%">
 +
<?php echo JText::_('COM_HELLOWORLD_HELLOWORLDS_NAME') ;?>
 +
</th>
 +
<th width="5%">
 +
<?php echo JText::_('COM_HELLOWORLD_PUBLISHED'); ?>
 +
</th>
 +
<th width="2%">
 +
<?php echo JText::_('COM_HELLOWORLD_ID'); ?>
 +
</th>
 +
</tr>
 +
</thead>
 +
<tfoot>
 +
<tr>
 +
<td colspan="5">
 +
<?php echo $this->pagination->getListFooter(); ?>
 +
</td>
 +
</tr>
 +
</tfoot>
 +
<tbody>
 +
<?php if (!empty($this->items)) : ?>
 +
<?php foreach ($this->items as $i => $row) :
 +
$link = JRoute::_('index.php?option=com_helloworld&task=helloworld.edit&id=' . $row->id);
 +
?>
 +
<tr>
 +
<td><?php echo $this->pagination->getRowOffset($i); ?></td>
 +
<td>
 +
<?php echo JHtml::_('grid.id', $i, $row->id); ?>
 +
</td>
 +
<td>
 +
<a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_HELLOWORLD_EDIT_HELLOWORLD'); ?>">
 +
<?php echo $row->greeting; ?>
 +
</a>
 +
</td>
 +
<td align="center">
 +
<?php echo JHtml::_('jgrid.published', $row->published, $i, 'helloworlds.', true, 'cb'); ?>
 +
</td>
 +
<td align="center">
 +
<?php echo $row->id; ?>
 +
</td>
 +
</tr>
 +
<?php endforeach; ?>
 +
<?php endif; ?>
 +
</tbody>
 
</table>
 
</table>
<div>
+
<input type="hidden" name="task" value=""/>
<input type="hidden" name="task" value="" />
+
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="boxchecked" value="0" />
+
<?php echo JHtml::_('form.token'); ?>
<?php echo JHtml::_('form.token'); ?>
 
</div>
 
 
</form>
 
</form>
 +
 
</source>
 
</source>
 
</span>
 
</span>
Line 102: Line 163:
 
* ''helloworld.edit''
 
* ''helloworld.edit''
 
* ''helloworld.add''
 
* ''helloworld.add''
read more about [[JController_and_its_subclass_usage_overview|subcontrollers...]]
 
  
These are compound tasks (''controller''.''task''). So two new controllers ''HelloWorldControllerHelloWorlds'' and ''HelloWorldControllerHelloWorld'' have to be coded.
+
These are compound tasks (''controller''.''task''). So two new controllers ''HelloWorldControllerHelloWorlds'' and ''HelloWorldControllerHelloWorld'' have to be coded. (To understand the difference between the two types of subcontrollers read more in this article: [[JController_and_its_subclass_usage_overview|subcontrollers...]])
  
 
<span id="admin/controllers/helloworlds.php">
 
<span id="admin/controllers/helloworlds.php">
''admin/controllers/helloworlds.php''
+
'''''admin/controllers/helloworlds.php'''''
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controlleradmin library
 
jimport('joomla.application.component.controlleradmin');
 
  
 
/**
 
/**
 
  * HelloWorlds Controller
 
  * HelloWorlds Controller
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldControllerHelloWorlds extends JControllerAdmin
 
class HelloWorldControllerHelloWorlds extends JControllerAdmin
Line 123: Line 189:
 
/**
 
/**
 
* Proxy for getModel.
 
* Proxy for getModel.
* @since 2.5
+
*
 +
* @param  string  $name    The model name. Optional.
 +
* @param  string  $prefix  The class prefix. Optional.
 +
* @param  array  $config  Configuration array for model. Optional.
 +
*
 +
* @return  object  The model.
 +
*
 +
* @since   1.6
 
*/
 
*/
public function getModel($name = 'HelloWorld', $prefix = 'HelloWorldModel')  
+
public function getModel($name = 'HelloWorld', $prefix = 'HelloWorldModel', $config = array('ignore_request' => true))
 
{
 
{
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
+
$model = parent::getModel($name, $prefix, $config);
 +
 
 
return $model;
 
return $model;
 
}
 
}
 
}
 
}
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
 
<span id="admin/controllers/helloworld.php">
 
<span id="admin/controllers/helloworld.php">
''admin/controllers/helloworld.php''
+
'''''admin/controllers/helloworld.php'''''
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controllerform library
 
jimport('joomla.application.component.controllerform');
 
  
 
/**
 
/**
 
  * HelloWorld Controller
 
  * HelloWorld Controller
 +
*
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
* @since      0.0.9
 
  */
 
  */
 
class HelloWorldControllerHelloWorld extends JControllerForm
 
class HelloWorldControllerHelloWorld extends JControllerForm
 
{
 
{
 
}
 
}
 +
 
</source>
 
</source>
 
</span>
 
</span>
Line 157: Line 241:
  
 
<span id="admin/views/helloworld/view.html.php">
 
<span id="admin/views/helloworld/view.html.php">
''admin/views/helloworld/view.html.php''
+
'''''admin/views/helloworld/view.html.php'''''
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
 
jimport('joomla.application.component.view');
 
  
 
/**
 
/**
 
  * HelloWorld View
 
  * HelloWorld View
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldViewHelloWorld extends JViewLegacy
 
class HelloWorldViewHelloWorld extends JViewLegacy
 
{
 
{
 
/**
 
/**
* display method of Hello view
+
* View form
* @return void
+
*
 +
* @var        form
 +
*/
 +
protected $form = null;
 +
 
 +
/**
 +
* Display the Hello World view
 +
*
 +
* @param  string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 +
*
 +
* @return void
 
*/
 
*/
public function display($tpl = null)  
+
public function display($tpl = null)
 
{
 
{
// get the Data
+
// Get the Data
$form = $this->get('Form');
+
$this->form = $this->get('Form');
$item = $this->get('Item');
+
$this->item = $this->get('Item');
  
 
// Check for errors.
 
// Check for errors.
if (count($errors = $this->get('Errors')))  
+
if (count($errors = $this->get('Errors')))
 
{
 
{
 
JError::raiseError(500, implode('<br />', $errors));
 
JError::raiseError(500, implode('<br />', $errors));
 +
 
return false;
 
return false;
 
}
 
}
// Assign the Data
+
 
$this->form = $form;
 
$this->item = $item;
 
  
 
// Set the toolbar
 
// Set the toolbar
Line 199: Line 299:
  
 
/**
 
/**
* Setting the toolbar
+
* Add the page title and toolbar.
 +
*
 +
* @return  void
 +
*
 +
* @since  1.6
 
*/
 
*/
protected function addToolBar()  
+
protected function addToolBar()
 
{
 
{
 
$input = JFactory::getApplication()->input;
 
$input = JFactory::getApplication()->input;
 +
 +
// Hide Joomla Administrator Main menu
 
$input->set('hidemainmenu', true);
 
$input->set('hidemainmenu', true);
 +
 
$isNew = ($this->item->id == 0);
 
$isNew = ($this->item->id == 0);
JToolBarHelper::title($isNew ? JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW')
+
 
                            : JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT'));
+
if ($isNew)
 +
{
 +
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW');
 +
}
 +
else
 +
{
 +
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT');
 +
}
 +
 
 +
JToolBarHelper::title($title, 'helloworld');
 
JToolBarHelper::save('helloworld.save');
 
JToolBarHelper::save('helloworld.save');
JToolBarHelper::cancel('helloworld.cancel', $isNew ? 'JTOOLBAR_CANCEL'
+
JToolBarHelper::cancel(
                                                  : 'JTOOLBAR_CLOSE');
+
'helloworld.cancel',
 +
$isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE'
 +
);
 
}
 
}
 
}
 
}
Line 221: Line 339:
  
 
<span id="admin/views/helloworld/tmpl/edit.php">
 
<span id="admin/views/helloworld/tmpl/edit.php">
''admin/views/helloworld/tmpl/edit.php''
+
'''''admin/views/helloworld/tmpl/edit.php'''''
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access
 
// No direct access
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
+
 
 
?>
 
?>
 
<form action="<?php echo JRoute::_('index.php?option=com_helloworld&layout=edit&id=' . (int) $this->item->id); ?>"
 
<form action="<?php echo JRoute::_('index.php?option=com_helloworld&layout=edit&id=' . (int) $this->item->id); ?>"
Line 248: Line 374:
 
     <?php echo JHtml::_('form.token'); ?>
 
     <?php echo JHtml::_('form.token'); ?>
 
</form>
 
</form>
 +
 
</source>
 
</source>
 
</span>
 
</span>
Line 256: Line 383:
  
 
<span id="admin/models/helloworld.php">
 
<span id="admin/models/helloworld.php">
''admin/models/helloworld.php''
+
'''''admin/models/helloworld.php'''''
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelform library
 
jimport('joomla.application.component.modeladmin');
 
  
 
/**
 
/**
 
  * HelloWorld Model
 
  * HelloWorld Model
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldModelHelloWorld extends JModelAdmin
 
class HelloWorldModelHelloWorld extends JModelAdmin
 
{
 
{
 
/**
 
/**
* Returns a reference to the a Table object, always creating it.
+
* Method to get a table object, load it if necessary.
 +
*
 +
* @param  string  $type    The table name. Optional.
 +
* @param  string  $prefix  The class prefix. Optional.
 +
* @param  array  $config  Configuration array for model. Optional.
 +
*
 +
* @return  JTable  A JTable object
 
*
 
*
* @param type The table type to instantiate
+
* @since   1.6
* @param string A prefix for the table class name. Optional.
 
* @param array Configuration array for model. Optional.
 
* @return JTable A database object
 
* @since 2.5
 
 
*/
 
*/
public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())  
+
public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())
 
{
 
{
 
return JTable::getInstance($type, $prefix, $config);
 
return JTable::getInstance($type, $prefix, $config);
 
}
 
}
 +
 
/**
 
/**
 
* Method to get the record form.
 
* Method to get the record form.
 
*
 
*
* @param array $data Data for the form.
+
* @param   array   $data     Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
+
* @param   boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
+
*
* @since 2.5
+
* @return mixed   A JForm object on success, false on failure
 +
*
 +
* @since   1.6
 
*/
 
*/
public function getForm($data = array(), $loadData = true)  
+
public function getForm($data = array(), $loadData = true)
 
{
 
{
 
// Get the form.
 
// Get the form.
$form = $this->loadForm('com_helloworld.helloworld', 'helloworld',
+
$form = $this->loadForm(
                        array('control' => 'jform', 'load_data' => $loadData));
+
'com_helloworld.helloworld',
if (empty($form))  
+
'helloworld',
 +
array(
 +
'control' => 'jform',
 +
'load_data' => $loadData
 +
)
 +
);
 +
 
 +
if (empty($form))
 
{
 
{
 
return false;
 
return false;
 
}
 
}
 +
 
return $form;
 
return $form;
 
}
 
}
 +
 
/**
 
/**
 
* Method to get the data that should be injected in the form.
 
* Method to get the data that should be injected in the form.
 
*
 
*
* @return mixed The data for the form.
+
* @return mixed The data for the form.
* @since 2.5
+
*
 +
* @since   1.6
 
*/
 
*/
protected function loadFormData()  
+
protected function loadFormData()
 
{
 
{
 
// Check the session for previously entered form data.
 
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_helloworld.edit.helloworld.data', array());
+
$data = JFactory::getApplication()->getUserState(
if (empty($data))  
+
'com_helloworld.edit.helloworld.data',
 +
array()
 +
);
 +
 
 +
if (empty($data))
 
{
 
{
 
$data = $this->getItem();
 
$data = $this->getItem();
 
}
 
}
 +
 
return $data;
 
return $data;
 
}
 
}
 
}
 
}
 +
 
</source>
 
</source>
 
</span>
 
</span>
Line 325: Line 480:
  
 
<span id="admin/models/forms/helloworld.xml">
 
<span id="admin/models/forms/helloworld.xml">
''admin/models/forms/helloworld.xml''
+
'''''admin/models/forms/helloworld.xml'''''
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
Line 331: Line 486:
 
<fieldset>
 
<fieldset>
 
<field
 
<field
name="id"
+
name="id"
type="hidden"
+
type="hidden"
/>
+
/>
 
<field
 
<field
name="greeting"
+
name="greeting"
type="text"
+
type="text"
label="COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL"
+
label="COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_GREETING_DESC"
+
description="COM_HELLOWORLD_HELLOWORLD_GREETING_DESC"
size="40"
+
size="40"
class="inputbox"
+
class="inputbox"
default=""
+
default=""
/>
+
/>
 
</fieldset>
 
</fieldset>
 
</form>
 
</form>
 
</source>
 
</source>
 
</span>
 
</span>
 +
 +
Note: ''COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL'' and ''COM_HELLOWORLD_HELLOWORLD_GREETING_DESC'' are an alias for ''COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL'' and ''COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC'' respectively.
 +
Here we are using different label and description to convey two different meanings in two different sections, but they can be easily kept equal.
  
 
== Packaging the component ==
 
== Packaging the component ==
Line 381: Line 539:
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/forms/index.html]]''
+
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/controllers/index.html]]''
+
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
 +
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
 +
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/tmpl/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_head.php|admin/views/helloworlds/tmpl/default_head.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_body.php|admin/views/helloworlds/tmpl/default_body.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_foot.php|admin/views/helloworlds/tmpl/default_foot.php]]''
 
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
* ''[[#admin/language/index.html|admin/language/index.html]]''
+
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/index.html]]''
* ''[[#admin/language/en-GB/index.html|admin/language/en-GB/index.html]]''
+
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/en-GB/index.html]]''
* ''[[#admin/language/en-GB/en-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
+
* ''[[J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
* ''[[#admin/language/en-GB/en-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
+
* ''[[J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
* ''[[#language/en-GB/en-GB.com_helloworld.sys.ini|language/en-GB/en-GB.com_helloworld.sys.ini]]''
 
  
Create a compressed file of this directory or directly download the [https://github.com/joomla/Joomla-3.2-Hello-World-Component/archive/step-9-adding-backend-actions.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.
+
Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-9-adding-backend-actions.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
 
''helloworld.xml''
 
''helloworld.xml''
<source lang="xml">
+
<source lang="xml" highlight="13,69,70">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="2.5.0" method="upgrade">
+
<extension type="component" version="3.2.0" method="upgrade">
  
<name>Hello World!</name>
+
<name>COM_HELLOWORLD</name>
 
<!-- The following elements are optional and free of formatting constraints -->
 
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>November 2009</creationDate>
+
<creationDate>January 2014</creationDate>
 
<author>John Doe</author>
 
<author>John Doe</author>
 
<authorEmail>john.doe@example.org</authorEmail>
 
<authorEmail>john.doe@example.org</authorEmail>
Line 435: Line 591:
 
</sql>
 
</sql>
 
</uninstall>
 
</uninstall>
<update> <!-- Runs on update; New in 2.5 -->
+
<update> <!-- Runs on update; New since J2.5 -->
 
<schemas>
 
<schemas>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
Line 451: Line 607:
 
<folder>views</folder>
 
<folder>views</folder>
 
<folder>models</folder>
 
<folder>models</folder>
<folder>language</folder>
 
 
</files>
 
</files>
 +
 +
        <languages folder="site/language">
 +
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
        </languages>
  
 
<administration>
 
<administration>
 
<!-- Administration Menu Section -->
 
<!-- Administration Menu Section -->
<menu>COM_HELLOWORLD_MENU</menu>
+
<menu link='index.php?option=com_helloworld'>COM_HELLOWORLD_MENU</menu>
 
<!-- Administration Main File Copy Section -->
 
<!-- Administration Main File Copy Section -->
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
Line 474: Line 633:
 
<!-- views files section -->
 
<!-- views files section -->
 
<folder>views</folder>
 
<folder>views</folder>
                        <!-- admin languages files section -->
 
                        <folder>language</folder>
 
 
<!-- controllers files section -->
 
<!-- controllers files section -->
 
<folder>controllers</folder>
 
<folder>controllers</folder>
</files>
+
</files>
 +
<languages folder="admin/language">
 +
        <language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
 +
</languages>
 
</administration>
 
</administration>
 +
 
</extension>
 
</extension>
 
</source>
 
</source>
Line 495: Line 657:
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:betweenbrain|Matt Thomas]]
 
*[[User:betweenbrain|Matt Thomas]]
 +
*[[User:Gunjanpatel|Gunjan Patel]]
 +
*[[User:Scionescire|Scionescire]]
  
 
[[Category:Joomla! 3.0]]
 
[[Category:Joomla! 3.0]]

Revision as of 09:39, 30 April 2015

Joomla! 
3.x
<translate> Tutorial</translate>
<translate> Developing an MVC Component</translate>

{{Chunk:Developing a Model-View-Controller (MVC) Component for Joomla!3.1 - Contents/<translate> en</translate>}} <translate> This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.</translate>

<translate> Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in This series).</translate>



Copyedit.png
This Page Needs Your Help

This page is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


Introduction[edit]

This tutorial is part of the Developing a MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this.

Adding a toolbar[edit]

In Joomla, the administrator interacts generally with components through the use of a toolbar. In the file 'admin/views/helloworlds/view.html.php' put this content. It will create a basic toolbar and a title for the component.

The arguments used in, for example, JToolBarHelper::addNew is used to set a controller instance which will be used after button is clicked. Further details below in the adding specific controllers section.

admin/views/helloworlds/view.html.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorlds View
 *
 * @since  0.0.1
 */
class HelloWorldViewHelloWorlds extends JViewLegacy
{
	/**
	 * Display the Hello World view
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  void
	 */
	function display($tpl = null)
	{
		// Get data from the model
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode('<br />', $errors));

			return false;
		}

		// Set the toolbar
		$this->addToolBar();

		// Display the template
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolBar()
	{
		JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'));
		JToolBarHelper::addNew('helloworld.add');
		JToolBarHelper::editList('helloworld.edit');
		JToolBarHelper::deleteList('', 'helloworlds.delete');
	}
}

You can find other classic backend actions in the administrator/includes/toolbar.php file of your Joomla installation.

Since the view can perform some actions, we have to add some input data. With your favorite file manager and editor, put in the file admin/views/helloworlds/tmpl/default.php

admin/views/helloworlds/tmpl/default.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
<form action="index.php?option=com_helloworld&view=helloworlds" method="post" id="adminForm" name="adminForm">
	<table class="table table-striped table-hover">
		<thead>
		<tr>
			<th width="1%"><?php echo JText::_('COM_HELLOWORLD_NUM'); ?></th>
			<th width="2%">
				<?php echo JHtml::_('grid.checkall'); ?>
			</th>
			<th width="90%">
				<?php echo JText::_('COM_HELLOWORLD_HELLOWORLDS_NAME') ;?>
			</th>
			<th width="5%">
				<?php echo JText::_('COM_HELLOWORLD_PUBLISHED'); ?>
			</th>
			<th width="2%">
				<?php echo JText::_('COM_HELLOWORLD_ID'); ?>
			</th>
		</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="5">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
		<tbody>
			<?php if (!empty($this->items)) : ?>
				<?php foreach ($this->items as $i => $row) :
					$link = JRoute::_('index.php?option=com_helloworld&task=helloworld.edit&id=' . $row->id);
				?>
					<tr>
						<td><?php echo $this->pagination->getRowOffset($i); ?></td>
						<td>
							<?php echo JHtml::_('grid.id', $i, $row->id); ?>
						</td>
						<td>
							<a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_HELLOWORLD_EDIT_HELLOWORLD'); ?>">
								<?php echo $row->greeting; ?>
							</a>
						</td>
						<td align="center">
							<?php echo JHtml::_('jgrid.published', $row->published, $i, 'helloworlds.', true, 'cb'); ?>
						</td>
						<td align="center">
							<?php echo $row->id; ?>
						</td>
					</tr>
				<?php endforeach; ?>
			<?php endif; ?>
		</tbody>
	</table>
	<input type="hidden" name="task" value=""/>
	<input type="hidden" name="boxchecked" value="0"/>
	<?php echo JHtml::_('form.token'); ?>
</form>

Adding specific controllers[edit]

Three actions have been added:

  • helloworlds.delete
  • helloworld.edit
  • helloworld.add

These are compound tasks (controller.task). So two new controllers HelloWorldControllerHelloWorlds and HelloWorldControllerHelloWorld have to be coded. (To understand the difference between the two types of subcontrollers read more in this article: subcontrollers...)

admin/controllers/helloworlds.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorlds Controller
 *
 * @since  0.0.1
 */
class HelloWorldControllerHelloWorlds extends JControllerAdmin
{
	/**
	 * Proxy for getModel.
	 *
	 * @param   string  $name    The model name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  object  The model.
	 *
	 * @since   1.6
	 */
	public function getModel($name = 'HelloWorld', $prefix = 'HelloWorldModel', $config = array('ignore_request' => true))
	{
		$model = parent::getModel($name, $prefix, $config);

		return $model;
	}
}

admin/controllers/helloworld.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorld Controller
 *
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 * @since       0.0.9
 */
class HelloWorldControllerHelloWorld extends JControllerForm
{
}

Adding an editing view[edit]

With your favorite file manager and editor, put a file admin/views/helloworld/view.html.php containing:

admin/views/helloworld/view.html.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorld View
 *
 * @since  0.0.1
 */
class HelloWorldViewHelloWorld extends JViewLegacy
{
	/**
	 * View form
	 *
	 * @var         form
	 */
	protected $form = null;

	/**
	 * Display the Hello World view
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  void
	 */
	public function display($tpl = null)
	{
		// Get the Data
		$this->form = $this->get('Form');
		$this->item = $this->get('Item');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode('<br />', $errors));

			return false;
		}


		// Set the toolbar
		$this->addToolBar();

		// Display the template
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolBar()
	{
		$input = JFactory::getApplication()->input;

		// Hide Joomla Administrator Main menu
		$input->set('hidemainmenu', true);

		$isNew = ($this->item->id == 0);

		if ($isNew)
		{
			$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW');
		}
		else
		{
			$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT');
		}

		JToolBarHelper::title($title, 'helloworld');
		JToolBarHelper::save('helloworld.save');
		JToolBarHelper::cancel(
			'helloworld.cancel',
			$isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE'
		);
	}
}

This view will display data using a layout.

Put a file admin/views/helloworld/tmpl/edit.php containing

admin/views/helloworld/tmpl/edit.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die('Restricted access');

?>
<form action="<?php echo JRoute::_('index.php?option=com_helloworld&layout=edit&id=' . (int) $this->item->id); ?>"
    method="post" name="adminForm" id="adminForm">
    <div class="form-horizontal">
        <fieldset class="adminform">
            <legend><?php echo JText::_('COM_HELLOWORLD_HELLOWORLD_DETAILS'); ?></legend>
            <div class="row-fluid">
                <div class="span6">
                    <?php foreach ($this->form->getFieldset() as $field): ?>
                        <div class="control-group">
                            <div class="control-label"><?php echo $field->label; ?></div>
                            <div class="controls"><?php echo $field->input; ?></div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </fieldset>
    </div>
    <input type="hidden" name="task" value="helloworld.edit" />
    <?php echo JHtml::_('form.token'); ?>
</form>

Adding a model and modifying the existing one[edit]

The HelloWorldViewHelloWorld view asks form and data from a model. This model has to provide a getTable, a getForm method and a loadData method (called from the JModelAdmin controller)

admin/models/helloworld.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorld Model
 *
 * @since  0.0.1
 */
class HelloWorldModelHelloWorld extends JModelAdmin
{
	/**
	 * Method to get a table object, load it if necessary.
	 *
	 * @param   string  $type    The table name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JTable  A JTable object
	 *
	 * @since   1.6
	 */
	public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())
	{
		return JTable::getInstance($type, $prefix, $config);
	}

	/**
	 * Method to get the record form.
	 *
	 * @param   array    $data      Data for the form.
	 * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
	 *
	 * @return  mixed    A JForm object on success, false on failure
	 *
	 * @since   1.6
	 */
	public function getForm($data = array(), $loadData = true)
	{
		// Get the form.
		$form = $this->loadForm(
			'com_helloworld.helloworld',
			'helloworld',
			array(
				'control' => 'jform',
				'load_data' => $loadData
			)
		);

		if (empty($form))
		{
			return false;
		}

		return $form;
	}

	/**
	 * Method to get the data that should be injected in the form.
	 *
	 * @return  mixed  The data for the form.
	 *
	 * @since   1.6
	 */
	protected function loadFormData()
	{
		// Check the session for previously entered form data.
		$data = JFactory::getApplication()->getUserState(
			'com_helloworld.edit.helloworld.data',
			array()
		);

		if (empty($data))
		{
			$data = $this->getItem();
		}

		return $data;
	}
}

This model inherits from the JModelAdmin class and uses its loadForm method. This method searches for forms in the forms folder. With your favorite file manager and editor, put a file admin/models/forms/helloworld.xml containing:

admin/models/forms/helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<form>
	<fieldset>
		<field
				name="id"
				type="hidden"
				/>
		<field
				name="greeting"
				type="text"
				label="COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL"
				description="COM_HELLOWORLD_HELLOWORLD_GREETING_DESC"
				size="40"
				class="inputbox"
				default=""
				/>
	</fieldset>
</form>

Note: COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL and COM_HELLOWORLD_HELLOWORLD_GREETING_DESC are an alias for COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL and COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC respectively. Here we are using different label and description to convey two different meanings in two different sections, but they can be easily kept equal.

Packaging the component[edit]

Content of your code directory

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>January 2014</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<version>0.0.9</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.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>helloworld.php</filename>
		<filename>controller.php</filename>
		<folder>views</folder>
		<folder>models</folder>
	</files>

        <languages folder="site/language">
		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
        </languages>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld'>COM_HELLOWORLD_MENU</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>helloworld.php</filename>
			<filename>controller.php</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
			<!-- controllers files section -->
			<folder>controllers</folder>
		</files>
		<languages folder="admin/language">
        		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
		</languages>
	</administration>

</extension>

Info non-talk.png
General Information

Please create a pull request or issue at https://github.com/joomla/Joomla-3.2-Hello-World-Component for any code descprepancies or if editing any of the source code on this page.

J3.x:Developing a MVC Component/Navigate

Contributors[edit]