Actions

J2.5

Difference between revisions of "Developing a MVC Component/Basic backend"

From Joomla! Documentation

< J2.5:Developing a MVC Component
(Packaging the component)
m (Create the general controller)
(26 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{future|1.6}}
+
{{version/tutor|2.5}}
 
+
{{Chunk:Developing a Model-View-Controller (MVC) Component for Joomla!2.5 - Contents}}
== Articles in this series ==
+
{{Chunk:Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Contents}}
+
  
 
== Introduction ==
 
== Introduction ==
This tutorial is part of the [[Developing a Model-View-Controller (MVC) Component for Joomla!1.6]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.
+
This tutorial is part of the [[Developing a Model-View-Controller (MVC) Component for Joomla!2.5]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.
 +
 
 +
And check the "discussion" tab for some clarifications.
  
 
== Basic backend ==
 
== Basic backend ==
Line 16: Line 16:
 
// 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 controller library
 
// import joomla controller library
 
jimport('joomla.application.component.controller');
 
jimport('joomla.application.component.controller');
 
+
 
// Get an instance of the controller prefixed by HelloWorld
 
// Get an instance of the controller prefixed by HelloWorld
 
$controller = JController::getInstance('HelloWorld');
 
$controller = JController::getInstance('HelloWorld');
 
+
 
// Perform the Request task
 
// Perform the Request task
 
$controller->execute(JRequest::getCmd('task'));
 
$controller->execute(JRequest::getCmd('task'));
 
+
 
// Redirect if set by the controller
 
// Redirect if set by the controller
 
$controller->redirect();
 
$controller->redirect();
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
 
== Create the general controller ==
 
== Create the general controller ==
The entry point now get an instance of a ''HelloWorld'' prefixed controller. Let create a basic controller for the administrator part:
+
The entry point now gets an instance of a ''HelloWorld'' prefixed controller. Let's create a basic controller for the administrator part:
  
 
<span id="admin/controller.php">
 
<span id="admin/controller.php">
Line 40: Line 41:
 
// 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 controller library
 
// import Joomla controller library
 
jimport('joomla.application.component.controller');
 
jimport('joomla.application.component.controller');
 
+
 
/**
 
/**
 
  * General Controller of HelloWorld component
 
  * General Controller of HelloWorld component
Line 57: Line 58:
 
{
 
{
 
// set default view if not set
 
// set default view if not set
JRequest::setVar('view', JRequest::getCmd('view', 'HelloWorlds'));
+
$input = JFactory::getApplication()->input;
 
+
$input->set('view', $input->getCmd('view', 'HelloWorlds'));
 +
 
// call parent behavior
 
// call parent behavior
 
parent::display($cachable);
 
parent::display($cachable);
 
}
 
}
 
}
 
}
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
This controller will display the 'HelloWorlds'' view by default.
+
This controller will display the 'HelloWorlds' view by default.
  
 
== Create the view ==
 
== Create the view ==
Line 208: Line 211:
  
 
== Create the model ==
 
== Create the model ==
The ''HelloWorlds'' view asks the model for data. In Joomla!1.6, there is a class able to manage list of data: ''JModelList''. Class ''JModelList'' and inherited classes needs only one method:
+
The ''HelloWorlds'' view asks the model for data. In Joomla, there is a class able to manage a list of data: ''JModelList''. Class ''JModelList'' and inherited classes need only one method:
* ''getListQuery'' which constructs and SQL query
+
* ''getListQuery'' which constructs an SQL query
  
 
and two states:
 
and two states:
Line 215: Line 218:
 
* ''list.limit'' for determining the list length
 
* ''list.limit'' for determining the list length
  
''getItems'' and ''getPagination'' method are defined in JModelList class. They don't need to be defined in the ''HelloWorldModelHelloWorlds'' class.
+
The ''getItems'' and ''getPagination'' methods are defined in JModelList class. They don't need to be defined in the ''HelloWorldModelHelloWorlds'' class.
  
 
<span id="admin/models/helloworlds.php">
 
<span id="admin/models/helloworlds.php">
Line 256: Line 259:
 
Content of your code directory
 
Content of your code directory
 
* ''[[#helloworld.xml|helloworld.xml]]''
 
* ''[[#helloworld.xml|helloworld.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|site/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_02#site/helloworld.php|site/helloworld.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/helloworld.php|site/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_02#site/controller.php|site/controller.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/controller.php|site/controller.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|site/views/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|site/views/helloworld/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/helloworld/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_04#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_04#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|site/views/helloworld/tmpl/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/helloworld/tmpl/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_02#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|site/models/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/models/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#site/models/helloworld.php|site/models/helloworld.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#site/models/helloworld.php|site/models/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/index.html]]''
 
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
 
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
 
* ''[[#admin/controller.php|admin/controller.php]]''
 
* ''[[#admin/controller.php|admin/controller.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/sql/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/sql/updates/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/updates/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/sql/updates/mysql/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/updates/mysql/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/models/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/models/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/models/fields/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/models/fields/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
 
* ''[[#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
 
* ''[[#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/views/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/views/helloworlds/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworlds/index.html]]''
 
* ''[[#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
 
* ''[[#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/views/helloworlds/tmpl/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworlds/tmpl/index.html]]''
 
* ''[[#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_head.php|admin/views/helloworlds/tmpl/default_head.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_head.php|admin/views/helloworlds/tmpl/default_head.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_body.php|admin/views/helloworlds/tmpl/default_body.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_body.php|admin/views/helloworlds/tmpl/default_body.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_foot.php|admin/views/helloworlds/tmpl/default_foot.php]]''
 
* ''[[#admin/views/helloworlds/tmpl/default_foot.php|admin/views/helloworlds/tmpl/default_foot.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_01#index.html|admin/tables/index.html]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/tables/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!1.6_-_Part_06#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
+
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
  
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11394/58231/com_helloworld-1.6-part07.zip archive] and install it using the extension manager of Joomla!1.6. 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 [http://joomlacode.org/gf/download/frsrelease/11394/58397/com_helloworld-1.6-part07.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">
Line 298: Line 301:
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.6.0" method="upgrade">
+
<extension type="component" version="2.5.0" method="upgrade">
 
<name>Hello World!</name>
 
<name>Hello World!</name>
 
<creationDate>November 2009</creationDate>
 
<creationDate>November 2009</creationDate>
Line 319: Line 322:
 
</sql>
 
</sql>
 
</uninstall>
 
</uninstall>
<update> <!-- Runs on update; New in 1.6 -->
+
<update> <!-- Runs on update; New in 2.5 -->
 
<schemas>
 
<schemas>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
Line 354: Line 357:
 
== Navigate ==
 
== Navigate ==
  
[[Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Part 06|Prev: Using the database]]
+
[[Developing a Model-View-Controller (MVC) Component for Joomla!2.5 - Part 06|Prev: Using the database]]
[[Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Part 08|Next: Adding language management]]
+
[[Developing a Model-View-Controller (MVC) Component for Joomla!2.5 - Part 08|Next: Adding language management]]
  
 
== Contributors ==
 
== Contributors ==
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:cdemko|Christophe Demko]]
 +
*[[User:oaksu|Ozgur Aksu]]
 +
*[[User:presto|Preston Smith]]
  
 
[[Category:Development]]
 
[[Category:Development]]
[[category:Joomla! 1.6]]
+
[[Category:Joomla! 1.6]]
[[category:Manual]]
+
[[Category:Joomla! 1.7]]
 +
[[Category:Joomla! 2.5]]

Revision as of 12:25, 11 January 2013


Introduction

This tutorial is part of the Developing a Model-View-Controller (MVC) Component for Joomla!2.5 tutorial. You are encouraged to read the previous parts of the tutorial before reading this.

And check the "discussion" tab for some clarifications.

Basic backend

Designing the backend interface leads us to create at least a Model-View-Controller triptych. We have to modify the administrator entry point of our component, the admin/helloworld.php file

admin/helloworld.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import joomla controller library
jimport('joomla.application.component.controller');
 
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
 
// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
 
// Redirect if set by the controller
$controller->redirect();

Create the general controller

The entry point now gets an instance of a HelloWorld prefixed controller. Let's create a basic controller for the administrator part:

admin/controller.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller');
 
/**
 * General Controller of HelloWorld component
 */
class HelloWorldController extends JController
{
        /**
         * display task
         *
         * @return void
         */
        function display($cachable = false) 
        {
                // set default view if not set
                $input = JFactory::getApplication()->input;
                $input->set('view', $input->getCmd('view', 'HelloWorlds'));
 
                // call parent behavior
                parent::display($cachable);
        }
}

This controller will display the 'HelloWorlds' view by default.

Create the view

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

admin/views/helloworlds/view.html.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
/**
 * HelloWorlds View
 */
class HelloWorldViewHelloWorlds extends JView
{
        /**
         * HelloWorlds view display method
         * @return void
         */
        function display($tpl = null) 
        {
                // Get data from the model
                $items = $this->get('Items');
                $pagination = $this->get('Pagination');
 
                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JError::raiseError(500, implode('<br />', $errors));
                        return false;
                }
                // Assign data to the view
                $this->items = $items;
                $this->pagination = $pagination;
 
                // Display the template
                parent::display($tpl);
        }
}

In Joomla, views display data using layout. With your favorite file manager and editor, put a file admin/views/helloworlds/tmpl/default.php containing

admin/views/helloworlds/tmpl/default.php

<?php
// No direct access to this file
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">
        <table class="adminlist">
                <thead><?php echo $this->loadTemplate('head');?></thead>
                <tfoot><?php echo $this->loadTemplate('foot');?></tfoot>
                <tbody><?php echo $this->loadTemplate('body');?></tbody>
        </table>
</form>

This layout calls several sub-layout (head, foot and body). Each sub-layout corresponds to a file prefixed by the name of the main layout (default), and an underscore.

Put a file admin/views/helloworlds/tmpl/default_head.php containing

admin/views/helloworlds/tmpl/default_head.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
<tr>
        <th width="5">
                <?php echo JText::_('COM_HELLOWORLD_HELLOWORLD_HEADING_ID'); ?>
        </th>
        <th width="20">
                <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
        </th>                   
        <th>
                <?php echo JText::_('COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING'); ?>
        </th>
</tr>

checkAll is a javascript function defined in the Joomla core able to check all items.

Put a file admin/views/helloworlds/tmpl/default_body.php containing

admin/views/helloworlds/tmpl/default_body.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
<?php foreach($this->items as $i => $item): ?>
        <tr class="row<?php echo $i % 2; ?>">
                <td>
                        <?php echo $item->id; ?>
                </td>
                <td>
                        <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                </td>
                <td>
                        <?php echo $item->greeting; ?>
                </td>
        </tr>
<?php endforeach; ?>

JHtml::_ is a helper function able to display several HTML output. In this case, it will display a checkbox for the item.

Put a file admin/views/helloworlds/tmpl/default_foot.php containing

admin/views/helloworlds/tmpl/default_foot.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
<tr>
        <td colspan="3"><?php echo $this->pagination->getListFooter(); ?></td>
</tr>

JPagination is a Joomla class able to manage and display pagination object.

Create the model

The HelloWorlds view asks the model for data. In Joomla, there is a class able to manage a list of data: JModelList. Class JModelList and inherited classes need only one method:

  • getListQuery which constructs an SQL query

and two states:

  • list.start for determining the list offset
  • list.limit for determining the list length

The getItems and getPagination methods are defined in JModelList class. They don't need to be defined in the HelloWorldModelHelloWorlds class.

admin/models/helloworlds.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
 * HelloWorldList Model
 */
class HelloWorldModelHelloWorlds extends JModelList
{
        /**
         * Method to build an SQL query to load the list data.
         *
         * @return      string  An SQL query
         */
        protected function getListQuery()
        {
                // Create a new query object.           
                $db = JFactory::getDBO();
                $query = $db->getQuery(true);
                // Select some fields
                $query->select('id,greeting');
                // From the hello table
                $query->from('#__helloworld');
                return $query;
        }
}

The _populateState method is, by default, automatically called when a state is read by the getState method.

Packaging the component

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="2.5.0" method="upgrade">
        <name>Hello World!</name>
        <creationDate>November 2009</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>
        <version>0.0.7</version>
        <description>Description of the Hello World component ...</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 in 2.5 -->
                <schemas>
                        <schemapath type="mysql">sql/updates/mysql</schemapath>
                </schemas>
        </update>
 
        <files folder="site">
                <filename>index.html</filename>
                <filename>helloworld.php</filename>
                <filename>controller.php</filename>
                <folder>views</folder>
                <folder>models</folder>
        </files>
 
        <administration>
                <menu>Hello World!</menu>
                <files folder="admin">
                        <filename>index.html</filename>
                        <filename>helloworld.php</filename>
                        <filename>controller.php</filename>
                        <folder>sql</folder>
                        <folder>tables</folder>
                        <folder>models</folder>
                        <!-- views files section -->
                        <folder>views</folder>
                </files>                
        </administration>
</extension>

Now you can see in your component hello-world an array with two colums, two rows and checkboxes. You can click the checkboxes in order to select the different options you want.

Navigate

Prev: Using the database Next: Adding language management

Contributors