<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Memberclicks</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Memberclicks"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Memberclicks"/>
	<updated>2026-06-23T09:24:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Plugin/Events/System&amp;diff=15883</id>
		<title>J1.5:Plugin/Events/System</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Plugin/Events/System&amp;diff=15883"/>
		<updated>2009-10-13T19:15:36Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* onAfterRoute */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Development]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
===Overview===&lt;br /&gt;
In a standard installation of Joomla! 1.5 we have several predefined events which, when triggered, call functions in the associated plugins.  For more information on plugins, look [[plugins:create_plugin|here]].&lt;br /&gt;
&lt;br /&gt;
This topic is aimed at &amp;quot;global&amp;quot; system events, including those triggered on every page load (onAfterInitialise, onAfterRoute, onAfterDispatch, onAfterRender), those supporting search within multiple plugins (onSearch, onSearchArea) and those supporting the presentation of web services (onGetWebServices). Visit [[Tutorial:Plugins|the plugins tutorial]] for a complete list over available core events.&lt;br /&gt;
&lt;br /&gt;
=== onAfterInitialise ===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This event is triggered after the framework has loaded and the applicaiton initialise method has been called.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Called in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*index.php&lt;br /&gt;
*administrator/index.php&lt;br /&gt;
&lt;br /&gt;
===onAfterRoute===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This event is triggered after the framework has loaded and initialised and the router has route the client request.&lt;br /&gt;
&lt;br /&gt;
Routing is the process of examining the request environment to determine which component should receive the request. The component optional parameters are then set in the request object to be processed when the application is being dispatched.&lt;br /&gt;
&lt;br /&gt;
When this event triggers the router has parsed the route and pushed the request parameters into JRequest for retrieval by the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* index.php&lt;br /&gt;
* administrator/index.php&lt;br /&gt;
&lt;br /&gt;
===onAfterDispatch===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
This event is triggered after the framework has dispatched the application.&lt;br /&gt;
&lt;br /&gt;
Dispatching is the process of pulling the option from the request object and mapping them to a component. If the component do not exist, it handles determining a default component to dispatch.&lt;br /&gt;
&lt;br /&gt;
When this event is triggered the output of the component is available in the document buffer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* index.php&lt;br /&gt;
* administrator/index.php&lt;br /&gt;
&lt;br /&gt;
===onAfterRender===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
This event is triggered after the framework has rendered the application.&lt;br /&gt;
&lt;br /&gt;
Rendering is the process of pushing the document buffers into the template placeholders, retrieving data from the document and pushing it into the into the JResponse buffer.&lt;br /&gt;
&lt;br /&gt;
When this event is triggered the output of the application is available in the response buffer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* index.php&lt;br /&gt;
* administrator/index.php&lt;br /&gt;
&lt;br /&gt;
===onSearch===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This event is triggered by a variety of search related operations. It is a request for a&lt;br /&gt;
plugin to return the result of a search request. The rows must return the following fields, which are used in a common display routine:&lt;br /&gt;
&lt;br /&gt;
* href&lt;br /&gt;
* title&lt;br /&gt;
* section&lt;br /&gt;
* created&lt;br /&gt;
* text&lt;br /&gt;
* browsernav&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The target search string.&lt;br /&gt;
* A string matching option (exact|any|all).&lt;br /&gt;
* A string ordering option (newest|oldest|popular|alpha|category)&lt;br /&gt;
* An array if restricted to areas, null if search all.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Array of stdClass objects with members as described above.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* administrator/components/com_statistics/admin.statistics.php&lt;br /&gt;
* components/com_search/search.php&lt;br /&gt;
* plugins/search/categories.php&lt;br /&gt;
* plugins/search/contacts.php&lt;br /&gt;
* plugins/search/content.php&lt;br /&gt;
* plugins/search/newsfeeds.php&lt;br /&gt;
* plugins/search/sections.php&lt;br /&gt;
* plugins/search/weblinks.php&lt;br /&gt;
* plugins/xmlrpc/joomla.php&lt;br /&gt;
&lt;br /&gt;
===onSearchAreas===&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This appears to be a request for plugins to identify which &amp;quot;areas&amp;quot; they provide&lt;br /&gt;
search facilities for.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An associative array of area names, indexed by the area identifier. For example, array( &#039;categories&#039; =&amp;gt; &#039;Categories&#039; ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* components/com_search/search.php&lt;br /&gt;
* plugins/search/categories.php&lt;br /&gt;
* plugins/search/contacts.php&lt;br /&gt;
* plugins/search/content.php&lt;br /&gt;
* plugins/search/newsfeeds.php&lt;br /&gt;
* plugins/search/sections.php&lt;br /&gt;
* plugins/search/weblinks.php&lt;br /&gt;
&lt;br /&gt;
===onGetWebServices===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Description&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is an introspection request for plugins that provide web services.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Parameters&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Return Value&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An array of associative arrays. The outer array is indexed by the service method name and&lt;br /&gt;
contains an array with the following elements:&lt;br /&gt;
&lt;br /&gt;
* [&#039;function&#039;] The method to be invoked, typically a string like &#039;ClassName::staticMethod&#039;&lt;br /&gt;
* [&#039;docstring&#039;] A human-readable definition of the method&#039;s purpose.&lt;br /&gt;
* [&#039;signature&#039;] An array identifying the types of the method&#039;s parameters. See the global variables $xmlrpc* for more information.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Used in files&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* plugins/xmlrpc/blogger.php&lt;br /&gt;
* plugins/xmlrpc/joomla.php&lt;br /&gt;
* xmlrpc/index.php&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&lt;br /&gt;
This is an example system plugin.  Please note that because system plugins are loaded before any other event group, they may also contain any other event.&lt;br /&gt;
&lt;br /&gt;
The following class would be located in the file &amp;lt;code&amp;gt;/plugins/system/example.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
// no direct access&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Example system plugin&lt;br /&gt;
 */&lt;br /&gt;
class plgSystemExample extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	 * Constructor&lt;br /&gt;
	 *&lt;br /&gt;
	 * For php4 compatability we must not use the __constructor as a constructor for plugins&lt;br /&gt;
	 * because func_get_args ( void ) returns a copy of all passed arguments NOT references.&lt;br /&gt;
	 * This causes problems with cross-referencing necessary for the observer design pattern.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @access	protected&lt;br /&gt;
	 * @param	object	$subject The object to observe&lt;br /&gt;
	 * @param 	array   $config  An array that holds the plugin configuration&lt;br /&gt;
	 * @since	1.0&lt;br /&gt;
	 */&lt;br /&gt;
	function plgSystemCache( &amp;amp;$subject, $config )&lt;br /&gt;
	{&lt;br /&gt;
		parent::__construct( $subject, $config );&lt;br /&gt;
&lt;br /&gt;
		// Do some extra initialisation in this constructor if required&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Do something onAfterInitialise &lt;br /&gt;
	 */&lt;br /&gt;
	function onAfterInitialise()&lt;br /&gt;
	{&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Do something onAfterRoute &lt;br /&gt;
	 */&lt;br /&gt;
	function onAfterRoute()&lt;br /&gt;
	{&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Do something onAfterDispatch &lt;br /&gt;
	 */&lt;br /&gt;
	function onAfterDispatch()&lt;br /&gt;
	{&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Do something onAfterRender &lt;br /&gt;
	 */&lt;br /&gt;
	function onAfterRender()&lt;br /&gt;
	{&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following XML document would be located in the file &amp;lt;code&amp;gt;/plugins/system/example.xml&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;system&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;name&amp;gt;System - Example&amp;lt;/name&amp;gt;&lt;br /&gt;
	&amp;lt;author&amp;gt;Author&amp;lt;/author&amp;gt;&lt;br /&gt;
	&amp;lt;creationDate&amp;gt;Month 2008&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
	&amp;lt;copyright&amp;gt;Copyright (C) 2008 Holder. All rights reserved.&amp;lt;/copyright&amp;gt;&lt;br /&gt;
	&amp;lt;license&amp;gt;GNU General Public License&amp;lt;/license&amp;gt;&lt;br /&gt;
	&amp;lt;authorEmail&amp;gt;email&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
	&amp;lt;authorUrl&amp;gt;url&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
	&amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
	&amp;lt;description&amp;gt;An example system plugin&amp;lt;/description&amp;gt;&lt;br /&gt;
	&amp;lt;files&amp;gt;&lt;br /&gt;
		&amp;lt;filename plugin=&amp;quot;example&amp;quot;&amp;gt;example.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
	&amp;lt;/files&amp;gt;&lt;br /&gt;
	&amp;lt;params&amp;gt;&lt;br /&gt;
  		&amp;lt;param name=&amp;quot;example&amp;quot;&lt;br /&gt;
  		type=&amp;quot;text&amp;quot;&lt;br /&gt;
  		default=&amp;quot;&amp;quot;&lt;br /&gt;
  		label=&amp;quot;Example&amp;quot;&lt;br /&gt;
  		description=&amp;quot;An example text parameter&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/params&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15871</id>
		<title>J1.5:Developing a MVC Component/Creating an Administrator Interface</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15871"/>
		<updated>2009-10-12T21:05:07Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Link reference for the Joomla! engine */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ambox&lt;br /&gt;
| type  = notice&lt;br /&gt;
| image = notice&lt;br /&gt;
| text  = This {{thingamabob}} has been divided into three sections, two new articles are added. Especially this page needs a review&lt;br /&gt;
&amp;lt;small&amp;gt;(August 2009)&amp;lt;/small&amp;gt;}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first three tutorials, we have developed a MVC component that retrieves its data from a table in the database. Currently, there is no way to add data to the database except to do it manually using another tool. In the next articles of this tutorial, we will develop an administrator section for our component which will make it possible to manage the entries in the database.&lt;br /&gt;
&lt;br /&gt;
This article, [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface | Part 4 - Creating an Administrator Interface ]], will be an article with no new source code for our Hello component but we will go into some basic details of the MVC pattern. In the frontend solution (site section) we have developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were taken by the hand to trust the default handling of the code. This is going to change in the Backend or Administration section of our Hello component.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The frontend is used for presenting the users with content and allowing certain logged in users to manipulate the content, the backend is responsible for administrating the website framework (structuring / managing / controlling / maintaining). This division between site-content and administration is a fundamental aspect of the Joomla! architecture.&lt;br /&gt;
&lt;br /&gt;
=== Entrance points ===&lt;br /&gt;
From the XML file of our frontend example it was already obvious that there would be an administration part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
  &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!--  Administration Menu Section --&amp;gt; &lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt; &lt;br /&gt;
  &amp;lt;!--  Administration Main File Copy Section --&amp;gt; &lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;/files&amp;gt;&lt;br /&gt;
  &amp;lt;/administration&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only the .sql files were of use and only during installation for our frontend view, the other two files have no content besides generating a blank page. Access your websites file system at your hosting provider (or on your own server) and browse through the directories after installing the frontend com_hello component. You may have noticed that our Hello component is to be found twice:&lt;br /&gt;
 &amp;lt;root&amp;gt;/components/com_hello&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/components/com_hello&lt;br /&gt;
&lt;br /&gt;
These two sub-directories link to the previously explained site-content and administration. Administrator interactions explicitly go via the administrator sub-directory, where guest or registered users will enter the default entrance on the root:&lt;br /&gt;
 &amp;lt;root&amp;gt;/index.php&lt;br /&gt;
Administrative users will have to log in, and after logging in they will enter your site via:&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/index.php&lt;br /&gt;
&lt;br /&gt;
With the different access points it is easy to grasp that with setting up the administrator section the naming conventions have no dependency with the site section. Whilst the MVC pattern is also applicable for the administrator section this implies that identical Controls, Views and Models naming can (and sometimes must) be used as in the site section.&lt;br /&gt;
&lt;br /&gt;
== MVC pattern interaction ==&lt;br /&gt;
[[image:MVC joomla.png|frameless|right]]In [[Developing a Model-View-Controller Component - Part 1]] the figure on the right was used to explain the focus of the first three parts of this &#039;&#039;Developing a Model-View-Controller Component tutorial&#039;&#039;. Now we will use this figure to explain how decisions are made on what is going to be displayed and how to manipulate this.&lt;br /&gt;
&lt;br /&gt;
=== Example roll-out ===&lt;br /&gt;
For explanation purposes an easy to grasp example will be used. A library has the main function of lending books to registered users. Simply laid out there are three tables:&lt;br /&gt;
* users&lt;br /&gt;
* books&lt;br /&gt;
* relation&lt;br /&gt;
&lt;br /&gt;
Lets keep it all very simple. The users are addressed by Id and Name. The books are identified by Id and Title and the relation contains both Ids and the date of lending.&lt;br /&gt;
&lt;br /&gt;
[[image:Library Example.png|400px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The example is carefully chosen and will help in explaining the Joomla! architecture in more detail. The administrative side of our Hello component is not even that complex with only one table to manage. After the explanation of this chapter it should be easy to follow the tutorial in the succeeding chapters&lt;br /&gt;
&lt;br /&gt;
=== Mapping a Joomla! MVC component from the example ===&lt;br /&gt;
In this example we will assume that administrative actions (add, edit, delete) are tasks that are to be performed by the administrator. For the frontend user only the view of the Relation table is interesting (&amp;quot;when do I have to bring back the books?&amp;quot;). This example shows the entire list and ignores all privacy stuff that could be taken care of by letting registered users only see their own books (&#039;&#039;Hint&#039;&#039;: &amp;lt;code&amp;gt;if ($user-&amp;gt;registered) {}&amp;lt;/code&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
Just like our frontend Hello component, for this library component only the default view is being used in the frontend. It lists the relational table, left joining the other two tables to obtain a human readable list of lend books. &lt;br /&gt;
 Alice | One flew over ... | 12 aug 2009&lt;br /&gt;
 Alice | Celeb talk        | 12 aug 2009&lt;br /&gt;
 Mark  | Joomla!           | 15 aug 2009&lt;br /&gt;
&lt;br /&gt;
With respect to the administration part it is important to understand that we have one default and three dedicated views, each controlling three tasks:&lt;br /&gt;
* &amp;lt;Component name default view&amp;gt;&lt;br /&gt;
* User administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Book administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Relation administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
&lt;br /&gt;
==== Controllers ====&lt;br /&gt;
The main controller of the admin section needs to differentiate between the different Adds, Changes or Deletes that are requested. This is taken care of by creating sub-controllers for each view for handling their specific tasks.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controller.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/relation.php&lt;br /&gt;
&lt;br /&gt;
The controller is an important part of the MVC pattern. Not only does it take care of the requested tasks, it is also the initiator of instantiating the model with the same name and it is responsible for setting the view and the desired form for that view. The controller really justifies its name. &lt;br /&gt;
&lt;br /&gt;
Within the controller it is good to make a difference between &#039;&#039;&#039;activating tasks&#039;&#039;&#039; (for example the edit selection from a menu) and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; (for example the result of an edit trigger is the posted data).&lt;br /&gt;
&lt;br /&gt;
Typical controller functions look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function &amp;lt;activating task&amp;gt;()  // &amp;lt;-- edit, add, delete &lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;default&#039;  );     // &amp;lt;-- The default form is named here but in complex &lt;br /&gt;
                                                  //     views multiple layouts might be needed.&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function &amp;lt;resulting task&amp;gt;()  // &amp;lt;-- save, remove&lt;br /&gt;
{&lt;br /&gt;
	$model = $this-&amp;gt;getModel(&#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039;);&lt;br /&gt;
	if(!$model-&amp;gt;action() ) {    // &amp;lt;-- action could be delete() or store()&lt;br /&gt;
		$msg = JText::_( &#039;Error: Could not perform action&#039; );&lt;br /&gt;
	} else {&lt;br /&gt;
		$msg = JText::_( &#039;Action executed&#039; );&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	$this-&amp;gt;setRedirect( &#039;index.php?option=&amp;lt;componentname&amp;gt;&#039;, $msg );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A controller takes care of all tasks for that dedicated controller. After completing a resulting task the module will return to the main administration entrance point for that component, the main controller with the default view. Activating tasks enforce a new view with a form to display after first defining it.&lt;br /&gt;
&lt;br /&gt;
The explicit definition of the form within a view might raise some eyebrows but our examples are too simple. For the general understanding and consistency this field should mostly be &#039;&#039;default&#039;&#039;. In complex views multiple forms could be defined within one view.&lt;br /&gt;
&lt;br /&gt;
==== Models ====&lt;br /&gt;
The Controllers interact with their equally named Model counter part. In the frontend view the Model was only used to retrieve data. The backend has more controllers and thus also more model files. The backend model files not only are responsible for delivering data to the viewer but also take care of tasks initiated from the controller. A good model contains all actions required to manage a single table in the database.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/relation.php&lt;br /&gt;
&lt;br /&gt;
==== Views ====&lt;br /&gt;
Separate views are of course also required. For views and subsequent forms no forced naming conventions are required (linking to views is taken care of in the controller). In the following listing the Administrative tasks are identified as a subset for the different views. This choice is totally random and maybe even non-logical but that doesn&#039;t matter for the explanation. Just for example purposes I added also a different view, a delete view, that could be used for all the deletes for all administrative tasks asking an &amp;quot;Are you sure&amp;quot; display.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/&amp;lt;componentname&amp;gt;/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/users/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/books/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/relation/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;amp;nbsp;&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/delete/view.html.php    + .../tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: In general it is good practice to maintain one form per view because the view.html.php still has to deliver the content. With some basic logic you can enable, disable certain content but if this logic is becoming too complex start considering splitting up the view. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Sharing template parts amongst the different views (for uniform layouting of headers and titles of your component) can be done using the PHP &amp;lt;code&amp;gt;include / require;&amp;lt;/code&amp;gt;. There is one slight problem ... how to make the logical reference? In my modules I have a collector bin for general to use sniplets. Because it involved the views and forms I put this general bin in the views directory. The variable $pathToGeneralView needs to be defined somewhere in the first lines of your file and you have to make sure that the logical reference path is correct (the &#039;..&#039;s). In the following example the files marked with a &#039;*&#039; use the following code:&lt;br /&gt;
&lt;br /&gt;
 ./com_compname/views/general/navigate.header.php  &amp;lt;-- sniplet code for the header&lt;br /&gt;
 ./com_compname/views/general/navigate.footer.php  &amp;lt;-- sniplet code for the footer&lt;br /&gt;
 ./com_compname/views/mngtable1/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable1/tmpl/default.php *&lt;br /&gt;
 ./com_compname/views/mngtable2/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable2/tmpl/default.php *&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER[&#039;SCRIPT_NAME&#039;]));&lt;br /&gt;
$pathToGeneralView = str_replace(dirname($_SERVER[&#039;SCRIPT_NAME&#039;]),&#039;.&#039;,$pathToGeneralView );&lt;br /&gt;
$pathToGeneralView = $pathToGeneralView . &amp;quot;/../../general/&amp;quot;;  &amp;lt;-- returning path from current position. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.header.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;P&amp;gt;Do something    &lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.footer.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Giving the forms logical instead of the &#039;&#039;default&#039;&#039; naming is of course handy when having a lot of different views. Having also that much &#039;&#039;default&#039;&#039; forms could make you easily loose oversight. On the other hand the view.html.php can not be renamed and you are always forced to look at the directory name for the view name you are working in.&lt;br /&gt;
&lt;br /&gt;
=== Essential Interaction Parameters ===&lt;br /&gt;
Everything is in place:&lt;br /&gt;
* main and dedicated controllers;&lt;br /&gt;
* main and dedicated modules;&lt;br /&gt;
* different views and their forms.&lt;br /&gt;
&lt;br /&gt;
Just one big question remains: &#039;&#039;&#039;How to use them&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Three parameters are mandatory for letting Joomla! do its job:&lt;br /&gt;
* option&lt;br /&gt;
* controller&lt;br /&gt;
* task&lt;br /&gt;
&lt;br /&gt;
These three parameters are almost self explaining ;). The &#039;&#039;option&#039;&#039; part when developing a component is easy, always assign your component name to it. For component development consider this one as a constant, of course the Joomla! engine has more options than only components.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;controller&#039;&#039; and &#039;&#039;task&#039;&#039; parameters can be manipulated within your component anyway you want it to. &lt;br /&gt;
&lt;br /&gt;
==== How it all works together ====&lt;br /&gt;
Looking at the simplified MVC picture Joomla! the logical flow of interaction goes the following way:&lt;br /&gt;
# What is my entrance point? &lt;br /&gt;
#*The Joomla! engine discovers a logged in administrator and sets the entrance point to &amp;lt;root&amp;gt;/administrator/index.php otherwise it wil go to the &amp;lt;root&amp;gt;/index.php entrance.&lt;br /&gt;
# What option is requested? &lt;br /&gt;
#*The Joomla! engine reads the option variable and discovers that a component named &amp;lt;componentname&amp;gt; is requested. The entrance point becomes: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
# Is there need to access a dedicated controller? &lt;br /&gt;
#* The Joomla! engine reads the controller variable and discovers that a dedicated controller is required: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/controllers/&amp;lt;dedicatedcontroller&amp;gt;.php&lt;br /&gt;
# Is there a task that needs to be addressed? &lt;br /&gt;
#* The identified controller is handed the task value as parameter. &lt;br /&gt;
# The Model is derived from the controller and instantiated.&lt;br /&gt;
# The View and Form are set in the controller and initiated to become active.&lt;br /&gt;
&lt;br /&gt;
=== How to add interaction ===&lt;br /&gt;
Within HTML there are two common ways to interact with Joomla!:&lt;br /&gt;
# reference to a link&lt;br /&gt;
# form submission post / get&lt;br /&gt;
&lt;br /&gt;
==== Link reference for the Joomla! engine ====&lt;br /&gt;
Remember the &#039;&#039;&#039;activating tasks&#039;&#039;&#039; and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; mentioned earlier? Most activating tasks are initiated by a link. In case of the Library example the site section overview could be copied to the admin section. This default view will now be extended and every cell will become a link for editing the specific database element.&lt;br /&gt;
&lt;br /&gt;
Using the Library example, the template PHP code without looping control will contain the following code:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=users&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idu );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=books&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idb );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;title&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=relation&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idr );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;date&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within each clickable field the three mandatory parameters to manipulate MVC can be identified. In addition there is one user parameter for handling the correct index in the controller task (cid). These parameter are separated by &#039;&amp;amp;&#039;. Do not use spaces in your variables this might screw-up parameter handling in certain browsers. After looping all text entries will be clickable and trigger the corresponding controller with the correct row id in the associated table.&lt;br /&gt;
&lt;br /&gt;
 [Alice} | [One flew over ...] | [12 aug 2009]&lt;br /&gt;
 [Alice] | [Celeb talk]        | [12 aug 2009]&lt;br /&gt;
 [Mark]  | [Joomla!]           | [15 aug 2009]&lt;br /&gt;
&lt;br /&gt;
==== Posting Form Data to the Joomla! Engine ====&lt;br /&gt;
After being initiated by an activating task, an input form view might be the result. The sniplet code below could be the result of clicking the first cell of the default component view that is clicked for editing ([Alice]:cid=3). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; id=&amp;quot;username&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;name;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;SubmitButton&amp;quot; value=&amp;quot;Save&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_library&amp;quot; /&amp;gt;                  // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;                    // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;save&amp;quot; /&amp;gt;                           // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;   // &amp;lt;-- user parameter, index in database for [Alice]&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The three Joomla! mandatory parameters are placed as hidden in the form. Hidden parameters are not shown in any way but will be added to the posting data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tip&#039;&#039;: when debugging this form, replace in the form tag &amp;lt;code&amp;gt;method=&amp;quot;post&amp;quot;&amp;lt;/code&amp;gt; temporarily with &amp;lt;code&amp;gt;method=&amp;quot;get&amp;quot;&amp;lt;/code&amp;gt;. All posted parameters will be shown in the URL of your browser. If the module is working undo this change. For one reason it looks sharper without all the parameters being shown in the URL and you avoid motivating people to manipulate the browser URL themselves. Of course one can look at the source code but using &#039;&#039;Post&#039;&#039; instead of &#039;&#039;Get&#039;&#039;, but this eliminates the first 90% of the earth population. The other reason is more technical and simply explained the method=&amp;quot;post&amp;quot; can contain more (complex) data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Remark&#039;&#039;: In some developed modules you may notice that developers have also added the &#039;&#039;view&#039;&#039; parameter. This is bad programming whilst the controller(s) should take care of the &#039;&#039;view&#039;&#039; and the &#039;&#039;form&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
The use of the three mandatory parameters and the different access points are clarified. Let&#039;s do something with this knowledge and extend the Hello component to the administrative section in the succeeding articles of this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15870</id>
		<title>J1.5:Developing a MVC Component/Creating an Administrator Interface</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15870"/>
		<updated>2009-10-12T21:03:26Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Link reference for the Joomla! engine */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ambox&lt;br /&gt;
| type  = notice&lt;br /&gt;
| image = notice&lt;br /&gt;
| text  = This {{thingamabob}} has been divided into three sections, two new articles are added. Especially this page needs a review&lt;br /&gt;
&amp;lt;small&amp;gt;(August 2009)&amp;lt;/small&amp;gt;}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first three tutorials, we have developed a MVC component that retrieves its data from a table in the database. Currently, there is no way to add data to the database except to do it manually using another tool. In the next articles of this tutorial, we will develop an administrator section for our component which will make it possible to manage the entries in the database.&lt;br /&gt;
&lt;br /&gt;
This article, [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface | Part 4 - Creating an Administrator Interface ]], will be an article with no new source code for our Hello component but we will go into some basic details of the MVC pattern. In the frontend solution (site section) we have developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were taken by the hand to trust the default handling of the code. This is going to change in the Backend or Administration section of our Hello component.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The frontend is used for presenting the users with content and allowing certain logged in users to manipulate the content, the backend is responsible for administrating the website framework (structuring / managing / controlling / maintaining). This division between site-content and administration is a fundamental aspect of the Joomla! architecture.&lt;br /&gt;
&lt;br /&gt;
=== Entrance points ===&lt;br /&gt;
From the XML file of our frontend example it was already obvious that there would be an administration part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
  &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!--  Administration Menu Section --&amp;gt; &lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt; &lt;br /&gt;
  &amp;lt;!--  Administration Main File Copy Section --&amp;gt; &lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;/files&amp;gt;&lt;br /&gt;
  &amp;lt;/administration&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only the .sql files were of use and only during installation for our frontend view, the other two files have no content besides generating a blank page. Access your websites file system at your hosting provider (or on your own server) and browse through the directories after installing the frontend com_hello component. You may have noticed that our Hello component is to be found twice:&lt;br /&gt;
 &amp;lt;root&amp;gt;/components/com_hello&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/components/com_hello&lt;br /&gt;
&lt;br /&gt;
These two sub-directories link to the previously explained site-content and administration. Administrator interactions explicitly go via the administrator sub-directory, where guest or registered users will enter the default entrance on the root:&lt;br /&gt;
 &amp;lt;root&amp;gt;/index.php&lt;br /&gt;
Administrative users will have to log in, and after logging in they will enter your site via:&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/index.php&lt;br /&gt;
&lt;br /&gt;
With the different access points it is easy to grasp that with setting up the administrator section the naming conventions have no dependency with the site section. Whilst the MVC pattern is also applicable for the administrator section this implies that identical Controls, Views and Models naming can (and sometimes must) be used as in the site section.&lt;br /&gt;
&lt;br /&gt;
== MVC pattern interaction ==&lt;br /&gt;
[[image:MVC joomla.png|frameless|right]]In [[Developing a Model-View-Controller Component - Part 1]] the figure on the right was used to explain the focus of the first three parts of this &#039;&#039;Developing a Model-View-Controller Component tutorial&#039;&#039;. Now we will use this figure to explain how decisions are made on what is going to be displayed and how to manipulate this.&lt;br /&gt;
&lt;br /&gt;
=== Example roll-out ===&lt;br /&gt;
For explanation purposes an easy to grasp example will be used. A library has the main function of lending books to registered users. Simply laid out there are three tables:&lt;br /&gt;
* users&lt;br /&gt;
* books&lt;br /&gt;
* relation&lt;br /&gt;
&lt;br /&gt;
Lets keep it all very simple. The users are addressed by Id and Name. The books are identified by Id and Title and the relation contains both Ids and the date of lending.&lt;br /&gt;
&lt;br /&gt;
[[image:Library Example.png|400px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The example is carefully chosen and will help in explaining the Joomla! architecture in more detail. The administrative side of our Hello component is not even that complex with only one table to manage. After the explanation of this chapter it should be easy to follow the tutorial in the succeeding chapters&lt;br /&gt;
&lt;br /&gt;
=== Mapping a Joomla! MVC component from the example ===&lt;br /&gt;
In this example we will assume that administrative actions (add, edit, delete) are tasks that are to be performed by the administrator. For the frontend user only the view of the Relation table is interesting (&amp;quot;when do I have to bring back the books?&amp;quot;). This example shows the entire list and ignores all privacy stuff that could be taken care of by letting registered users only see their own books (&#039;&#039;Hint&#039;&#039;: &amp;lt;code&amp;gt;if ($user-&amp;gt;registered) {}&amp;lt;/code&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
Just like our frontend Hello component, for this library component only the default view is being used in the frontend. It lists the relational table, left joining the other two tables to obtain a human readable list of lend books. &lt;br /&gt;
 Alice | One flew over ... | 12 aug 2009&lt;br /&gt;
 Alice | Celeb talk        | 12 aug 2009&lt;br /&gt;
 Mark  | Joomla!           | 15 aug 2009&lt;br /&gt;
&lt;br /&gt;
With respect to the administration part it is important to understand that we have one default and three dedicated views, each controlling three tasks:&lt;br /&gt;
* &amp;lt;Component name default view&amp;gt;&lt;br /&gt;
* User administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Book administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Relation administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
&lt;br /&gt;
==== Controllers ====&lt;br /&gt;
The main controller of the admin section needs to differentiate between the different Adds, Changes or Deletes that are requested. This is taken care of by creating sub-controllers for each view for handling their specific tasks.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controller.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/relation.php&lt;br /&gt;
&lt;br /&gt;
The controller is an important part of the MVC pattern. Not only does it take care of the requested tasks, it is also the initiator of instantiating the model with the same name and it is responsible for setting the view and the desired form for that view. The controller really justifies its name. &lt;br /&gt;
&lt;br /&gt;
Within the controller it is good to make a difference between &#039;&#039;&#039;activating tasks&#039;&#039;&#039; (for example the edit selection from a menu) and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; (for example the result of an edit trigger is the posted data).&lt;br /&gt;
&lt;br /&gt;
Typical controller functions look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function &amp;lt;activating task&amp;gt;()  // &amp;lt;-- edit, add, delete &lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;default&#039;  );     // &amp;lt;-- The default form is named here but in complex &lt;br /&gt;
                                                  //     views multiple layouts might be needed.&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function &amp;lt;resulting task&amp;gt;()  // &amp;lt;-- save, remove&lt;br /&gt;
{&lt;br /&gt;
	$model = $this-&amp;gt;getModel(&#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039;);&lt;br /&gt;
	if(!$model-&amp;gt;action() ) {    // &amp;lt;-- action could be delete() or store()&lt;br /&gt;
		$msg = JText::_( &#039;Error: Could not perform action&#039; );&lt;br /&gt;
	} else {&lt;br /&gt;
		$msg = JText::_( &#039;Action executed&#039; );&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	$this-&amp;gt;setRedirect( &#039;index.php?option=&amp;lt;componentname&amp;gt;&#039;, $msg );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A controller takes care of all tasks for that dedicated controller. After completing a resulting task the module will return to the main administration entrance point for that component, the main controller with the default view. Activating tasks enforce a new view with a form to display after first defining it.&lt;br /&gt;
&lt;br /&gt;
The explicit definition of the form within a view might raise some eyebrows but our examples are too simple. For the general understanding and consistency this field should mostly be &#039;&#039;default&#039;&#039;. In complex views multiple forms could be defined within one view.&lt;br /&gt;
&lt;br /&gt;
==== Models ====&lt;br /&gt;
The Controllers interact with their equally named Model counter part. In the frontend view the Model was only used to retrieve data. The backend has more controllers and thus also more model files. The backend model files not only are responsible for delivering data to the viewer but also take care of tasks initiated from the controller. A good model contains all actions required to manage a single table in the database.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/relation.php&lt;br /&gt;
&lt;br /&gt;
==== Views ====&lt;br /&gt;
Separate views are of course also required. For views and subsequent forms no forced naming conventions are required (linking to views is taken care of in the controller). In the following listing the Administrative tasks are identified as a subset for the different views. This choice is totally random and maybe even non-logical but that doesn&#039;t matter for the explanation. Just for example purposes I added also a different view, a delete view, that could be used for all the deletes for all administrative tasks asking an &amp;quot;Are you sure&amp;quot; display.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/&amp;lt;componentname&amp;gt;/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/users/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/books/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/relation/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;amp;nbsp;&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/delete/view.html.php    + .../tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: In general it is good practice to maintain one form per view because the view.html.php still has to deliver the content. With some basic logic you can enable, disable certain content but if this logic is becoming too complex start considering splitting up the view. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Sharing template parts amongst the different views (for uniform layouting of headers and titles of your component) can be done using the PHP &amp;lt;code&amp;gt;include / require;&amp;lt;/code&amp;gt;. There is one slight problem ... how to make the logical reference? In my modules I have a collector bin for general to use sniplets. Because it involved the views and forms I put this general bin in the views directory. The variable $pathToGeneralView needs to be defined somewhere in the first lines of your file and you have to make sure that the logical reference path is correct (the &#039;..&#039;s). In the following example the files marked with a &#039;*&#039; use the following code:&lt;br /&gt;
&lt;br /&gt;
 ./com_compname/views/general/navigate.header.php  &amp;lt;-- sniplet code for the header&lt;br /&gt;
 ./com_compname/views/general/navigate.footer.php  &amp;lt;-- sniplet code for the footer&lt;br /&gt;
 ./com_compname/views/mngtable1/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable1/tmpl/default.php *&lt;br /&gt;
 ./com_compname/views/mngtable2/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable2/tmpl/default.php *&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER[&#039;SCRIPT_NAME&#039;]));&lt;br /&gt;
$pathToGeneralView = str_replace(dirname($_SERVER[&#039;SCRIPT_NAME&#039;]),&#039;.&#039;,$pathToGeneralView );&lt;br /&gt;
$pathToGeneralView = $pathToGeneralView . &amp;quot;/../../general/&amp;quot;;  &amp;lt;-- returning path from current position. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.header.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;P&amp;gt;Do something    &lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.footer.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Giving the forms logical instead of the &#039;&#039;default&#039;&#039; naming is of course handy when having a lot of different views. Having also that much &#039;&#039;default&#039;&#039; forms could make you easily loose oversight. On the other hand the view.html.php can not be renamed and you are always forced to look at the directory name for the view name you are working in.&lt;br /&gt;
&lt;br /&gt;
=== Essential Interaction Parameters ===&lt;br /&gt;
Everything is in place:&lt;br /&gt;
* main and dedicated controllers;&lt;br /&gt;
* main and dedicated modules;&lt;br /&gt;
* different views and their forms.&lt;br /&gt;
&lt;br /&gt;
Just one big question remains: &#039;&#039;&#039;How to use them&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Three parameters are mandatory for letting Joomla! do its job:&lt;br /&gt;
* option&lt;br /&gt;
* controller&lt;br /&gt;
* task&lt;br /&gt;
&lt;br /&gt;
These three parameters are almost self explaining ;). The &#039;&#039;option&#039;&#039; part when developing a component is easy, always assign your component name to it. For component development consider this one as a constant, of course the Joomla! engine has more options than only components.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;controller&#039;&#039; and &#039;&#039;task&#039;&#039; parameters can be manipulated within your component anyway you want it to. &lt;br /&gt;
&lt;br /&gt;
==== How it all works together ====&lt;br /&gt;
Looking at the simplified MVC picture Joomla! the logical flow of interaction goes the following way:&lt;br /&gt;
# What is my entrance point? &lt;br /&gt;
#*The Joomla! engine discovers a logged in administrator and sets the entrance point to &amp;lt;root&amp;gt;/administrator/index.php otherwise it wil go to the &amp;lt;root&amp;gt;/index.php entrance.&lt;br /&gt;
# What option is requested? &lt;br /&gt;
#*The Joomla! engine reads the option variable and discovers that a component named &amp;lt;componentname&amp;gt; is requested. The entrance point becomes: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
# Is there need to access a dedicated controller? &lt;br /&gt;
#* The Joomla! engine reads the controller variable and discovers that a dedicated controller is required: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/controllers/&amp;lt;dedicatedcontroller&amp;gt;.php&lt;br /&gt;
# Is there a task that needs to be addressed? &lt;br /&gt;
#* The identified controller is handed the task value as parameter. &lt;br /&gt;
# The Model is derived from the controller and instantiated.&lt;br /&gt;
# The View and Form are set in the controller and initiated to become active.&lt;br /&gt;
&lt;br /&gt;
=== How to add interaction ===&lt;br /&gt;
Within HTML there are two common ways to interact with Joomla!:&lt;br /&gt;
# reference to a link&lt;br /&gt;
# form submission post / get&lt;br /&gt;
&lt;br /&gt;
==== Link reference for the Joomla! engine ====&lt;br /&gt;
Remember the &#039;&#039;&#039;activating tasks&#039;&#039;&#039; and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; mentioned earlier? Most activating tasks are initiated by a link. In case of the Library example the site section overview could be copied to the admin section. This default view will now be extended and every cell will become a link for editing the specific database element.&lt;br /&gt;
&lt;br /&gt;
Using the Library example, the template PHP code without looping control will contain the following code:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=users&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idu );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=books&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idb );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;title&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=relation&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idr );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;date&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within each clickable field the three mandatory parameters to manipulate MVC can be identified. In addation there is one user parameter for handling the correct index in the controller task (cid). These parameter are separated by &#039;&amp;amp;&#039;. Do not use spaces in your variables this might screw-up parameter handling in certain browsers. After looping all text entries will be clickable and trigger the corresponding controller with the correct row id in the associated table.&lt;br /&gt;
&lt;br /&gt;
 [Alice} | [One flew over ...] | [12 aug 2009]&lt;br /&gt;
 [Alice] | [Celeb talk]        | [12 aug 2009]&lt;br /&gt;
 [Mark]  | [Joomla!]           | [15 aug 2009]&lt;br /&gt;
&lt;br /&gt;
==== Posting Form Data to the Joomla! Engine ====&lt;br /&gt;
After being initiated by an activating task, an input form view might be the result. The sniplet code below could be the result of clicking the first cell of the default component view that is clicked for editing ([Alice]:cid=3). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; id=&amp;quot;username&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;name;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;SubmitButton&amp;quot; value=&amp;quot;Save&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_library&amp;quot; /&amp;gt;                  // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;                    // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;save&amp;quot; /&amp;gt;                           // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;   // &amp;lt;-- user parameter, index in database for [Alice]&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The three Joomla! mandatory parameters are placed as hidden in the form. Hidden parameters are not shown in any way but will be added to the posting data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tip&#039;&#039;: when debugging this form, replace in the form tag &amp;lt;code&amp;gt;method=&amp;quot;post&amp;quot;&amp;lt;/code&amp;gt; temporarily with &amp;lt;code&amp;gt;method=&amp;quot;get&amp;quot;&amp;lt;/code&amp;gt;. All posted parameters will be shown in the URL of your browser. If the module is working undo this change. For one reason it looks sharper without all the parameters being shown in the URL and you avoid motivating people to manipulate the browser URL themselves. Of course one can look at the source code but using &#039;&#039;Post&#039;&#039; instead of &#039;&#039;Get&#039;&#039;, but this eliminates the first 90% of the earth population. The other reason is more technical and simply explained the method=&amp;quot;post&amp;quot; can contain more (complex) data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Remark&#039;&#039;: In some developed modules you may notice that developers have also added the &#039;&#039;view&#039;&#039; parameter. This is bad programming whilst the controller(s) should take care of the &#039;&#039;view&#039;&#039; and the &#039;&#039;form&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
The use of the three mandatory parameters and the different access points are clarified. Let&#039;s do something with this knowledge and extend the Hello component to the administrative section in the succeeding articles of this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Adding_Backend_Actions&amp;diff=15856</id>
		<title>J1.5:Developing a MVC Component/Adding Backend Actions</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Adding_Backend_Actions&amp;diff=15856"/>
		<updated>2009-10-09T19:56:56Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This article focuses on adding functionality to the current &#039;&#039;dumb&#039;&#039; page/article for the administrator. For an administrator the current default view is pretty useless. It doesn&#039;t really do anything - all it does is display the entries that we have in our database.&lt;br /&gt;
&lt;br /&gt;
In order to make it useful, we need to add some buttons and links. This article extends the component with content management tasks. Add, Change and Delete are the typical tasks that will be added.&lt;br /&gt;
&lt;br /&gt;
==Adding interaction ==&lt;br /&gt;
Interaction will be added on two levels. Within the administrator framework by means of Toolbar extension and within the article itself by means of reference links and form postings. For basic understanding see [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]].&lt;br /&gt;
&lt;br /&gt;
=== The Toolbar ===&lt;br /&gt;
&lt;br /&gt;
You may have noticed the toolbar that appears at the top of other Joomla! component administrator panels. Our component needs one as well. Joomla! makes this very easy to do. We will add buttons Delete records, Edit records, and create New records. We will also add a title that will be displayed on our toolbar.&lt;br /&gt;
&lt;br /&gt;
This is done by adding code to the view. To add the buttons, we use static methods from the Joomla! JToolBarHelper class. The code looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JToolBarHelper::title(   JText::_( &#039;Hello Manager&#039; ), &#039;generic.png&#039; );&lt;br /&gt;
JToolBarHelper::deleteList();&lt;br /&gt;
JToolBarHelper::editListX();&lt;br /&gt;
JToolBarHelper::addNewX();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These three methods will create the appropriate buttons. The deleteList() method can optionally take up to three parameters - the first parameter is a string to display to the user to confirm that they want to delete the records. The second is the task that should be sent with the query (the default is &#039;remove&#039;), and the third is the text that should be displayed below the button.&lt;br /&gt;
&lt;br /&gt;
The editListX() and addNewX() methods can each take two optional parameters. The first is the task (which are by default edit and add, respectively), and the second is the text that should be displayed below the button.&lt;br /&gt;
&lt;br /&gt;
*You may have noticed the use of the JText::_ method in the template before and here as well. This is a handy function that makes component translation much easier. The JText::_ method will look up the string in your component language file and return the translated string. If no translation text is found, it will return the string that you passed to it. If you want to translate your component into another language, all you have to do is create a language file that will map the strings within the quotes to the translated version of the string.&lt;br /&gt;
&lt;br /&gt;
=== Checkboxes and Links ===&lt;br /&gt;
&lt;br /&gt;
We now have buttons. Two of those buttons operate on existing records. But how do we know which records to operate on? We have to let the user tell us. To do this, we need to add checkboxes to our table so that the user can select certain records. This is done in our template.&lt;br /&gt;
&lt;br /&gt;
In order to the add the checkboxes, we need to add an extra column into our table. We will add the column in between the two that we already have.&lt;br /&gt;
&lt;br /&gt;
In the header of the column, we will add a checkbox which can be used to toggle all the boxes below it on or off:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;th width=&amp;quot;20&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;checkbox&amp;quot; name=&amp;quot;toggle&amp;quot; value=&amp;quot;&amp;quot; onclick=&amp;quot;checkAll(&amp;lt;?php echo count( $this-&amp;gt;items ); ?&amp;gt;);&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Javascript checkAll function is a function that is built into the Joomla! base Javascript package that provides the functionality that we want here.&lt;br /&gt;
&lt;br /&gt;
Now we need to add the checkboxes into the individual rows. Joomla!&#039;s JHTML class has a method, JHTML::_(), which will generate our checkbox for us. We will add the following line to our loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$checked    = JHTML::_( &#039;grid.id&#039;, $i, $row-&amp;gt;id );&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
after the line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$row =&amp;amp; $this-&amp;gt;items[$i];&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we will add a cell in between the two that we already have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&lt;br /&gt;
    &amp;lt;?php echo $checked; ?&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be cumbersome to have to check the box that we want to edit and then move up and click the edit button. Therefore, we will add a link so that it will go straight to the greeting&#039;s edit form. We will add the following line after the call to the JHTML::_() method to generate the link HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$link = JRoute::_( &#039;index.php?option=com_hello&amp;amp;controller=hello&amp;amp;task=edit&amp;amp;cid[]=&#039;. $row-&amp;gt;id );&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we include the link in the cell showing the greeting text:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&lt;br /&gt;
    &amp;lt;a href=&amp;quot;&amp;lt;?php echo $link; ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;?php echo $row-&amp;gt;greeting; ?&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that this link points to the hello controller. This controller will handle the data manipulation of our greetings.&lt;br /&gt;
&lt;br /&gt;
If you recall from above, we had four hidden input fields at the bottom of our form. The first input field was named &#039;option&#039;. This field is necessary so that we stay in our component. The second input field was task. This form property gets set when one of the buttons in the toolbar is clicked. A Javascript error will result and the buttons will not work if this input field is omitted. The third input field is the boxchecked field. This field keeps track of the number of boxes that are checked. The edit and delete buttons will check to ensure that this is greater than zero and will not allow the form to be submitted if it is not. The fourth input field is the controller field. This is used to specify that tasks fired from this form will be handled by the hello controller.&lt;br /&gt;
&lt;br /&gt;
Here is the code for the completed default.php file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;?php defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;); ?&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot; name=&amp;quot;adminForm&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;editcell&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;table class=&amp;quot;adminlist&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;thead&amp;gt;&lt;br /&gt;
        &amp;lt;tr&amp;gt;&lt;br /&gt;
            &amp;lt;th width=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;?php echo JText::_( &#039;ID&#039; ); ?&amp;gt;&lt;br /&gt;
            &amp;lt;/th&amp;gt;&lt;br /&gt;
            &amp;lt;th width=&amp;quot;20&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;input type=&amp;quot;checkbox&amp;quot; name=&amp;quot;toggle&amp;quot; value=&amp;quot;&amp;quot; onclick=&amp;quot;checkAll(&amp;lt;?php echo count( $this-&amp;gt;items ); ?&amp;gt;);&amp;quot; /&amp;gt;&lt;br /&gt;
            &amp;lt;/th&amp;gt;&lt;br /&gt;
            &amp;lt;th&amp;gt;&lt;br /&gt;
                &amp;lt;?php echo JText::_( &#039;Greeting&#039; ); ?&amp;gt;&lt;br /&gt;
            &amp;lt;/th&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;            &lt;br /&gt;
    &amp;lt;/thead&amp;gt;&lt;br /&gt;
    &amp;lt;?php&lt;br /&gt;
    $k = 0;&lt;br /&gt;
    for ($i=0, $n=count( $this-&amp;gt;items ); $i &amp;lt; $n; $i++)&lt;br /&gt;
    {&lt;br /&gt;
        $row =&amp;amp; $this-&amp;gt;items[$i];&lt;br /&gt;
        $checked    = JHTML::_( &#039;grid.id&#039;, $i, $row-&amp;gt;id );&lt;br /&gt;
        $link = JRoute::_( &#039;index.php?option=com_hello&amp;amp;controller=hello&amp;amp;task=edit&amp;amp;cid[]=&#039;. $row-&amp;gt;id );&lt;br /&gt;
        &lt;br /&gt;
        ?&amp;gt;&lt;br /&gt;
        &amp;lt;tr class=&amp;quot;&amp;lt;?php echo &amp;quot;row$k&amp;quot;; ?&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
                &amp;lt;?php echo $row-&amp;gt;id; ?&amp;gt;&lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &amp;lt;?php echo $checked; ?&amp;gt;&lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
                &amp;lt;a href=&amp;quot;&amp;lt;?php echo $link; ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;?php echo $row-&amp;gt;greeting; ?&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;?php&lt;br /&gt;
        $k = 1 - $k;&lt;br /&gt;
    }&lt;br /&gt;
    ?&amp;gt;&lt;br /&gt;
    &amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_hello&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;boxchecked&amp;quot; value=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our hellos view is now complete.&lt;br /&gt;
&lt;br /&gt;
== Getting Down and Dirty: Doing the Real Work ==&lt;br /&gt;
&lt;br /&gt;
Now that the Hellos view is done, it is time to move to the Hello controller and model. This is where the real work will get done.&lt;br /&gt;
&lt;br /&gt;
==== The Hello Controller ====&lt;br /&gt;
&lt;br /&gt;
Our default controller just isn&#039;t going to cut it when it comes to doing work - all it is capable of doing is displaying views.&lt;br /&gt;
&lt;br /&gt;
We need to be able to handle the tasks that we are launching from the Hellos view: add, edit and remove. The singular named Hello controller is created (and located in the controllers sub-directory) to actually add, edit and remove the individual entries.&lt;br /&gt;
&lt;br /&gt;
Add and edit are essentially the same task: they both display a form to the user that allows a greeting to be edited. The only difference is that new displays a blank form, and edit displays a form with data already in it. Since they are similar, we will map the add task onto the edit task handler. This is specified in our constructor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * constructor (registers additional tasks to methods)&lt;br /&gt;
 * @return void&lt;br /&gt;
 */&lt;br /&gt;
function __construct()&lt;br /&gt;
{&lt;br /&gt;
    parent::__construct();&lt;br /&gt;
&lt;br /&gt;
    // Register Extra tasks&lt;br /&gt;
    $this-&amp;gt;registerTask( &#039;add&#039;  ,     &#039;edit&#039; );&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first parameter of JController::registerTask is the task to map, and the second is the method to map it to.&lt;br /&gt;
&lt;br /&gt;
We will start with handling the edit task. The controller&#039;s job is fairly simple for the edit task. All it has to do is specify the view and layout to load (the hello view and the form layout). We will also tell Joomla! to disable the mainmenu while we are editing our greeting. This prevents users from leaving unsaved records open.&lt;br /&gt;
&lt;br /&gt;
Our edit task handler looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * display the edit form&lt;br /&gt;
 * @return void&lt;br /&gt;
 */&lt;br /&gt;
function edit()&lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;hello&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;form&#039;  );&lt;br /&gt;
    JRequest::setVar(&#039;hidemainmenu&#039;, 1);&lt;br /&gt;
&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE on naming conventions:  The top calling program (hello.php) makes assumptions about the file names and class names of the controllers.  To summarize for this example: &lt;br /&gt;
&lt;br /&gt;
   Default controller path:    .../controller.php&lt;br /&gt;
   Default controller class name:  HellosController&lt;br /&gt;
&lt;br /&gt;
   Requested controller path .../controllers/&amp;lt;requestName&amp;gt;.php&lt;br /&gt;
   Requested controller class name:  HellosController&amp;lt;requestName&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== The Hello View ====&lt;br /&gt;
&lt;br /&gt;
The Hello view will display a form which will allow the user to edit a greeting. The display method if the hello view has to do a few simple tasks:&lt;br /&gt;
&lt;br /&gt;
* retrieve the data from the model&lt;br /&gt;
* create the toolbar&lt;br /&gt;
* pass the data into the template&lt;br /&gt;
* invoke the display() method to render the template&lt;br /&gt;
&lt;br /&gt;
This becomes a bit more complicated because the one view handles both the edit and add tasks. In our toolbar we want the user to know whether they are adding or editing, so we have to determine which task was fired.&lt;br /&gt;
&lt;br /&gt;
Since we are already retrieving the record that we want to display from the model, we can use this data to determine what task was fired. If the task was edit, then the id field of our record will have been set. If the task was new, then it will not have been set. This can be used to determine if we have a new record or an existing record.&lt;br /&gt;
&lt;br /&gt;
We will add two buttons to the toolbar: save and cancel. Though the functionality will be the same, we want to display different buttons depending on whether it is a new or existing record. If it is a new record, we will display cancel. If it already exists, we will display close.&lt;br /&gt;
&lt;br /&gt;
Thus our display method looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * display method of Hello view&lt;br /&gt;
 * @return void&lt;br /&gt;
 **/&lt;br /&gt;
function display($tpl = null)&lt;br /&gt;
{&lt;br /&gt;
    //get the hello&lt;br /&gt;
    $hello        =&amp;amp; $this-&amp;gt;get(&#039;Data&#039;);&lt;br /&gt;
    $isNew        = ($hello-&amp;gt;id &amp;lt; 1);&lt;br /&gt;
&lt;br /&gt;
    $text = $isNew ? JText::_( &#039;New&#039; ) : JText::_( &#039;Edit&#039; );&lt;br /&gt;
    JToolBarHelper::title(   JText::_( &#039;Hello&#039; ).&#039;: &amp;lt;small&amp;gt;&amp;lt;small&amp;gt;[ &#039; . $text.&#039; ]&amp;lt;/small&amp;gt;&amp;lt;/small&amp;gt;&#039; );&lt;br /&gt;
    JToolBarHelper::save();&lt;br /&gt;
    if ($isNew)  {&lt;br /&gt;
        JToolBarHelper::cancel();&lt;br /&gt;
    } else {&lt;br /&gt;
        // for existing items the button is renamed `close`&lt;br /&gt;
        JToolBarHelper::cancel( &#039;cancel&#039;, &#039;Close&#039; );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;assignRef(&#039;hello&#039;, $hello);&lt;br /&gt;
    parent::display($tpl);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== The Hello Model ====&lt;br /&gt;
&lt;br /&gt;
Our view needs data. Therefore, we need to create a model to model a hello.&lt;br /&gt;
&lt;br /&gt;
Our model will have two properties: _id and _data. _id will hold the id of the greeting and data will hold the data.&lt;br /&gt;
&lt;br /&gt;
We will start with a constructor, which will attempt to retrieve the id from the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Constructor that retrieves the ID from the request&lt;br /&gt;
 *&lt;br /&gt;
 * @access    public&lt;br /&gt;
 * @return    void&lt;br /&gt;
 */&lt;br /&gt;
function __construct()&lt;br /&gt;
{&lt;br /&gt;
    parent::__construct();&lt;br /&gt;
&lt;br /&gt;
    $array = JRequest::getVar(&#039;cid&#039;,  0, &#039;&#039;, &#039;array&#039;);&lt;br /&gt;
    $this-&amp;gt;setId((int)$array[0]);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JRequest::getVar() method is used to retrieve data from the request. The first parameter is the name of the form variable. The second parameter is the default value to assign if there is no value found. The third parameter is the name of the hash to retrieve the value from (get, post, etc), and the last value is the data type that should be forced on the value.&lt;br /&gt;
&lt;br /&gt;
Our constructor will take the first value from the cid array and assign it to the id.&lt;br /&gt;
&lt;br /&gt;
Our setId() method can be used to set our id. Changing the id that our model points to will mean the id points to the wrong data. Therefore, when we set the id, we will clear the data property:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Method to set the hello identifier&lt;br /&gt;
 *&lt;br /&gt;
 * @access    public&lt;br /&gt;
 * @param    int Hello identifier&lt;br /&gt;
 * @return    void&lt;br /&gt;
 */&lt;br /&gt;
function setId($id)&lt;br /&gt;
{&lt;br /&gt;
    // Set id and wipe data&lt;br /&gt;
    $this-&amp;gt;_id        = $id;&lt;br /&gt;
    $this-&amp;gt;_data    = null;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, we need a method to retrieve our data: getData()&lt;br /&gt;
&lt;br /&gt;
getData will check if the _data property has already been set. If it has, it will simply return it. Otherwise, it will load the data from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Method to get a hello&lt;br /&gt;
 * @return object with data&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
function &amp;amp;getData()&lt;br /&gt;
{&lt;br /&gt;
    // Load the data&lt;br /&gt;
    if (empty( $this-&amp;gt;_data )) {&lt;br /&gt;
        $query = &#039; SELECT * FROM #__hello &#039;.&lt;br /&gt;
                &#039;  WHERE id = &#039;.$this-&amp;gt;_id;&lt;br /&gt;
        $this-&amp;gt;_db-&amp;gt;setQuery( $query );&lt;br /&gt;
        $this-&amp;gt;_data = $this-&amp;gt;_db-&amp;gt;loadObject();&lt;br /&gt;
    }&lt;br /&gt;
    if (!$this-&amp;gt;_data) {&lt;br /&gt;
        $this-&amp;gt;_data = new stdClass();&lt;br /&gt;
        $this-&amp;gt;_data-&amp;gt;id = 0;&lt;br /&gt;
        $this-&amp;gt;_data-&amp;gt;greeting = null;&lt;br /&gt;
    }&lt;br /&gt;
    return $this-&amp;gt;_data;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== The Form ====&lt;br /&gt;
&lt;br /&gt;
Now all that is left is to create the form that the data will go into. Since we specified our layout as form, the form will go in a file in the tmpl directory of the hello view called form.php:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;?php defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;); ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot; name=&amp;quot;adminForm&amp;quot; id=&amp;quot;adminForm&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;col100&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;fieldset class=&amp;quot;adminform&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;legend&amp;gt;&amp;lt;?php echo JText::_( &#039;Details&#039; ); ?&amp;gt;&amp;lt;/legend&amp;gt;&lt;br /&gt;
        &amp;lt;table class=&amp;quot;admintable&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr&amp;gt;&lt;br /&gt;
            &amp;lt;td width=&amp;quot;100&amp;quot; align=&amp;quot;right&amp;quot; class=&amp;quot;key&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;label for=&amp;quot;greeting&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;?php echo JText::_( &#039;Greeting&#039; ); ?&amp;gt;:&lt;br /&gt;
                &amp;lt;/label&amp;gt;&lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
                &amp;lt;input class=&amp;quot;text_area&amp;quot; type=&amp;quot;text&amp;quot; name=&amp;quot;greeting&amp;quot; id=&amp;quot;greeting&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;hello-&amp;gt;greeting;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;/table&amp;gt;&lt;br /&gt;
    &amp;lt;/fieldset&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;clr&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_hello&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;hello-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that in addition to the input field, there is a hidden field for the id. The user doesn&#039;t need to edit the id (and shouldn&#039;t), so we silently pass it along in the form.&lt;br /&gt;
&lt;br /&gt;
==== Implementing the Functionality ====&lt;br /&gt;
&lt;br /&gt;
So far, our controller only handles two tasks: edit and new. However, we also have buttons to save, delete and cancel records. We need to write code to handle and perform these tasks.&lt;br /&gt;
&lt;br /&gt;
=== Saving a Record ===&lt;br /&gt;
&lt;br /&gt;
The logical next step is to implement the functionality to save a record. Normally, this would require some switches and logic to handle various cases, such as the difference between creating a new record (an INSERT query), and updating an existing query (an UPDATE query). Also, there are complexities involved in getting the data from the form and putting it into the query.&lt;br /&gt;
&lt;br /&gt;
The Joomla! framework takes care of a lot of this for you. The JTable class makes it easy to manipulate records in the database without having to worry about writing the SQL code that lies behind these updates. It also makes it easy to transfer data from an HTML form into the database.&lt;br /&gt;
&lt;br /&gt;
== Creating the Table Class ==&lt;br /&gt;
&lt;br /&gt;
The JTable class is an abstract class from which you can derive child classes to work with specific tables. To use it, you simply create a class that extends the JTable class, add your database fields as properties, and override the constructor to specify the name of the table and the primary key.&lt;br /&gt;
&lt;br /&gt;
Here is our JTable class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * Hello World table class&lt;br /&gt;
 * &lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4&lt;br /&gt;
 * @license        GNU/GPL&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Hello Table class&lt;br /&gt;
 *&lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 */&lt;br /&gt;
class TableHello extends JTable&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * Primary Key&lt;br /&gt;
     *&lt;br /&gt;
     * @var int&lt;br /&gt;
     */&lt;br /&gt;
    var $id = null;&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * @var string&lt;br /&gt;
     */&lt;br /&gt;
    var $greeting = null;&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Constructor&lt;br /&gt;
     *&lt;br /&gt;
     * @param object Database connector object&lt;br /&gt;
     */&lt;br /&gt;
    function TableHello( &amp;amp;$db ) {&lt;br /&gt;
        parent::__construct(&#039;#__hello&#039;, &#039;id&#039;, $db);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see here that we have defined our two fields: the id field and the greeting field. Then we have defined a constructor, which will call the constructor of the parent class and pass it the name of the table (hello), the name of the field which is the primary key (id), and the database connector object.&lt;br /&gt;
&lt;br /&gt;
This file should be called hello.php and it will go in a directory called tables in the administrator section of our component.&lt;br /&gt;
&lt;br /&gt;
== Implementing the Function in our Model ==&lt;br /&gt;
&lt;br /&gt;
We are now ready to add the method to the model which will save our record. We will call this method store. Our store() method will do three things: bind the data from the form to the TableHello object, check to ensure that the record is properly formed, and store the record in the database.&lt;br /&gt;
&lt;br /&gt;
Our method looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Method to store a record&lt;br /&gt;
 *&lt;br /&gt;
 * @access    public&lt;br /&gt;
 * @return    boolean    True on success&lt;br /&gt;
 */&lt;br /&gt;
function store()&lt;br /&gt;
{&lt;br /&gt;
    $row =&amp;amp; $this-&amp;gt;getTable();&lt;br /&gt;
&lt;br /&gt;
    $data = JRequest::get( &#039;post&#039; );&lt;br /&gt;
    // Bind the form fields to the hello table&lt;br /&gt;
    if (!$row-&amp;gt;bind($data)) {&lt;br /&gt;
        $this-&amp;gt;setError($this-&amp;gt;_db-&amp;gt;getErrorMsg());&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Make sure the hello record is valid&lt;br /&gt;
    if (!$row-&amp;gt;check()) {&lt;br /&gt;
        $this-&amp;gt;setError($this-&amp;gt;_db-&amp;gt;getErrorMsg());&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Store the web link table to the database&lt;br /&gt;
    if (!$row-&amp;gt;store()) {&lt;br /&gt;
        $this-&amp;gt;setError($this-&amp;gt;_db-&amp;gt;getErrorMsg());&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return true;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method gets added to the hello model.&lt;br /&gt;
&lt;br /&gt;
The method takes one parameter, which is an associative array of data that we want to store in the database. This can easily be retrieved from the request as will be seen later.&lt;br /&gt;
&lt;br /&gt;
You will see that the first line retrieves a reference to our JTable object. If we name our table properly, we don&#039;t have to specify its name - the JModel class knows where to find it. You may recall that we called our table class TableHello and put it in a file called hello.php in the tables directory. If you follow this convention, the JModel class can create your object automatically.&lt;br /&gt;
&lt;br /&gt;
The second line will retrieve the data from the form. The JRequest class makes this very easy. In this case, we are retrieving all of the variables that were submitted using the &#039;POST&#039; method. These will be returned as an associative array.&lt;br /&gt;
&lt;br /&gt;
The rest is easy - we bind, check and store. The bind() method will copy values from the array into the corresponding property of the table object. In this case, it will take the values of id and greeting and copy them to our TableHello object.&lt;br /&gt;
&lt;br /&gt;
The check() method will perform data verification. In the JTable() class, this method simply returns true. While this doesn&#039;t provide any value for us currently, by calling this method we make it possible to do data checking using our TableHello class in the future. This method can be overridden in our TableHello class with a method that performs the appropriate checks.&lt;br /&gt;
&lt;br /&gt;
The store() method will take the data that is in the object and store it in the database. If the id is 0, it will create a new record (INSERT), otherwise, it will update the existing record (UPDATE).&lt;br /&gt;
&lt;br /&gt;
== Adding the Task to the Controller ==&lt;br /&gt;
&lt;br /&gt;
We are now ready to add our task to the controller. Since the task that we are firing is called &#039;save&#039;, we must call our method &#039;save&#039;. This is simple:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * save a record (and redirect to main page)&lt;br /&gt;
 * @return void&lt;br /&gt;
 */&lt;br /&gt;
function save()&lt;br /&gt;
{&lt;br /&gt;
    $model = $this-&amp;gt;getModel(&#039;hello&#039;);&lt;br /&gt;
&lt;br /&gt;
    if ($model-&amp;gt;store()) {&lt;br /&gt;
        $msg = JText::_( &#039;Greeting Saved!&#039; );&lt;br /&gt;
    } else {&lt;br /&gt;
        $msg = JText::_( &#039;Error Saving Greeting&#039; );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Check the table in so it can be edited.... we are done with it anyway&lt;br /&gt;
    $link = &#039;index.php?option=com_hello&#039;;&lt;br /&gt;
    $this-&amp;gt;setRedirect($link, $msg);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All we do is get our model and invoke the store() method. Then we use the setRedirect() method to redirect back to our list of greetings. We also pass a message along, which will be displayed at the top of the page.&lt;br /&gt;
&lt;br /&gt;
=== Deleting a Record ===&lt;br /&gt;
&lt;br /&gt;
=== Implementing the Function in the Model ===&lt;br /&gt;
&lt;br /&gt;
In the model, we will retrieve the list of IDs to delete and call the JTable class to delete them. Here it is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Method to delete record(s)&lt;br /&gt;
 *&lt;br /&gt;
 * @access    public&lt;br /&gt;
 * @return    boolean    True on success&lt;br /&gt;
 */&lt;br /&gt;
function delete()&lt;br /&gt;
{&lt;br /&gt;
    $cids = JRequest::getVar( &#039;cid&#039;, array(0), &#039;post&#039;, &#039;array&#039; );&lt;br /&gt;
    $row =&amp;amp; $this-&amp;gt;getTable();&lt;br /&gt;
&lt;br /&gt;
    foreach($cids as $cid) {&lt;br /&gt;
        if (!$row-&amp;gt;delete( $cid )) {&lt;br /&gt;
            $this-&amp;gt;setError( $row-&amp;gt;getErrorMsg() );&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return true;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We invoke the JRequest::getVar() method to get the data from the request, then we invoke the $row-&amp;gt;delete() method to delete each row. By storing errors in the model we make it possible to retrieve them later if we so choose.&lt;br /&gt;
&lt;br /&gt;
=== Handling the Remove Task in the Controller ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the save() method which handled the save task:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * remove record(s)&lt;br /&gt;
 * @return void&lt;br /&gt;
 */&lt;br /&gt;
function remove()&lt;br /&gt;
{&lt;br /&gt;
    $model = $this-&amp;gt;getModel(&#039;hello&#039;);&lt;br /&gt;
    if(!$model-&amp;gt;delete()) {&lt;br /&gt;
        $msg = JText::_( &#039;Error: One or More Greetings Could not be Deleted&#039; );&lt;br /&gt;
    } else {&lt;br /&gt;
        $msg = JText::_( &#039;Greeting(s) Deleted&#039; );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;setRedirect( &#039;index.php?option=com_hello&#039;, $msg );&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Cancelling the Edit Operation ====&lt;br /&gt;
&lt;br /&gt;
To cancel the edit operation, all we have to do is redirect back to the main view:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * cancel editing a record&lt;br /&gt;
 * @return void&lt;br /&gt;
 */&lt;br /&gt;
function cancel()&lt;br /&gt;
{&lt;br /&gt;
    $msg = JText::_( &#039;Operation Cancelled&#039; );&lt;br /&gt;
    $this-&amp;gt;setRedirect( &#039;index.php?option=com_hello&#039;, $msg );&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
We have now implemented a basic backend to our component. We are now able to edit the entries that are viewed in the frontend. We have demonstrated the interaction between models, views and controllers. We have shown how the JTable class can be extended to provide easy access to tables in the database. It can also be seen how the JToolBarHelper class can be used to create button bars in components to present a standardized look between components.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
&lt;br /&gt;
The component can be downloaded at: [http://joomlacode.org/gf/download/frsrelease/8111/29436/com_hello4_01.zip com_hello4_01]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15855</id>
		<title>J1.5:Developing a MVC Component/Creating an Administrator Interface</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15855"/>
		<updated>2009-10-09T19:43:47Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Link reference for the Joomla! engine */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ambox&lt;br /&gt;
| type  = notice&lt;br /&gt;
| image = notice&lt;br /&gt;
| text  = This {{thingamabob}} has been divided into three sections, two new articles are added. Especially this page needs a review&lt;br /&gt;
&amp;lt;small&amp;gt;(August 2009)&amp;lt;/small&amp;gt;}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first three tutorials, we have developed a MVC component that retrieves its data from a table in the database. Currently, there is no way to add data to the database except to do it manually using another tool. In the next articles of this tutorial, we will develop an administrator section for our component which will make it possible to manage the entries in the database.&lt;br /&gt;
&lt;br /&gt;
This article, [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface | Part 4 - Creating an Administrator Interface ]], will be an article with no new source code for our Hello component but we will go into some basic details of the MVC pattern. In the frontend solution (site section) we have developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were taken by the hand to trust the default handling of the code. This is going to change in the Backend or Administration section of our Hello component.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The frontend is used for presenting the users with content and allowing certain logged in users to manipulate the content, the backend is responsible for administrating the website framework (structuring / managing / controlling / maintaining). This division between site-content and administration is a fundamental aspect of the Joomla! architecture.&lt;br /&gt;
&lt;br /&gt;
=== Entrance points ===&lt;br /&gt;
From the XML file of our frontend example it was already obvious that there would be an administration part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
  &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!--  Administration Menu Section --&amp;gt; &lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt; &lt;br /&gt;
  &amp;lt;!--  Administration Main File Copy Section --&amp;gt; &lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;/files&amp;gt;&lt;br /&gt;
  &amp;lt;/administration&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only the .sql files were of use and only during installation for our frontend view, the other two files have no content besides generating a blank page. Access your websites file system at your hosting provider (or on your own server) and browse through the directories after installing the frontend com_hello component. You may have noticed that our Hello component is to be found twice:&lt;br /&gt;
 &amp;lt;root&amp;gt;/components/com_hello&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/components/com_hello&lt;br /&gt;
&lt;br /&gt;
These two sub-directories link to the previously explained site-content and administration. Administrator interactions explicitly go via the administrator sub-directory, where guest or registered users will enter the default entrance on the root:&lt;br /&gt;
 &amp;lt;root&amp;gt;/index.php&lt;br /&gt;
Administrative users will have to log in, and after logging in they will enter your site via:&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/index.php&lt;br /&gt;
&lt;br /&gt;
With the different access points it is easy to grasp that with setting up the administrator section the naming conventions have no dependency with the site section. Whilst the MVC pattern is also applicable for the administrator section this implies that identical Controls, Views and Models naming can (and sometimes must) be used as in the site section.&lt;br /&gt;
&lt;br /&gt;
== MVC pattern interaction ==&lt;br /&gt;
[[image:MVC joomla.png|frameless|right]]In [[Developing a Model-View-Controller Component - Part 1]] the figure on the right was used to explain the focus of the first three parts of this &#039;&#039;Developing a Model-View-Controller Component tutorial&#039;&#039;. Now we will use this figure to explain how decisions are made on what is going to be displayed and how to manipulate this.&lt;br /&gt;
&lt;br /&gt;
=== Example roll-out ===&lt;br /&gt;
For explanation purposes an easy to grasp example will be used. A library has the main function of lending books to registered users. Simply laid out there are three tables:&lt;br /&gt;
* users&lt;br /&gt;
* books&lt;br /&gt;
* relation&lt;br /&gt;
&lt;br /&gt;
Lets keep it all very simple. The users are addressed by Id and Name. The books are identified by Id and Title and the relation contains both Ids and the date of lending.&lt;br /&gt;
&lt;br /&gt;
[[image:Library Example.png|400px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The example is carefully chosen and will help in explaining the Joomla! architecture in more detail. The administrative side of our Hello component is not even that complex with only one table to manage. After the explanation of this chapter it should be easy to follow the tutorial in the succeeding chapters&lt;br /&gt;
&lt;br /&gt;
=== Mapping a Joomla! MVC component from the example ===&lt;br /&gt;
In this example we will assume that administrative actions (add, edit, delete) are tasks that are to be performed by the administrator. For the frontend user only the view of the Relation table is interesting (&amp;quot;when do I have to bring back the books?&amp;quot;). This example shows the entire list and ignores all privacy stuff that could be taken care of by letting registered users only see their own books (&#039;&#039;Hint&#039;&#039;: &amp;lt;code&amp;gt;if ($user-&amp;gt;registered) {}&amp;lt;/code&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
Just like our frontend Hello component, for this library component only the default view is being used in the frontend. It lists the relational table, left joining the other two tables to obtain a human readable list of lend books. &lt;br /&gt;
 Alice | One flew over ... | 12 aug 2009&lt;br /&gt;
 Alice | Celeb talk        | 12 aug 2009&lt;br /&gt;
 Mark  | Joomla!           | 15 aug 2009&lt;br /&gt;
&lt;br /&gt;
With respect to the administration part it is important to understand that we have one default and three dedicated views, each controlling three tasks:&lt;br /&gt;
* &amp;lt;Component name default view&amp;gt;&lt;br /&gt;
* User administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Book administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Relation administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
&lt;br /&gt;
==== Controllers ====&lt;br /&gt;
The main controller of the admin section needs to differentiate between the different Adds, Changes or Deletes that are requested. This is taken care of by creating sub-controllers for each view for handling their specific tasks.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controller.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/relation.php&lt;br /&gt;
&lt;br /&gt;
The controller is an important part of the MVC pattern. Not only does it take care of the requested tasks, it is also the initiator of instantiating the model with the same name and it is responsible for setting the view and the desired form for that view. The controller really justifies its name. &lt;br /&gt;
&lt;br /&gt;
Within the controller it is good to make a difference between &#039;&#039;&#039;activating tasks&#039;&#039;&#039; (for example the edit selection from a menu) and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; (for example the result of an edit trigger is the posted data).&lt;br /&gt;
&lt;br /&gt;
Typical controller functions look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function &amp;lt;activating task&amp;gt;()  // &amp;lt;-- edit, add, delete &lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;default&#039;  );     // &amp;lt;-- The default form is named here but in complex &lt;br /&gt;
                                                  //     views multiple layouts might be needed.&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function &amp;lt;resulting task&amp;gt;()  // &amp;lt;-- save, remove&lt;br /&gt;
{&lt;br /&gt;
	$model = $this-&amp;gt;getModel(&#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039;);&lt;br /&gt;
	if(!$model-&amp;gt;action() ) {    // &amp;lt;-- action could be delete() or store()&lt;br /&gt;
		$msg = JText::_( &#039;Error: Could not perform action&#039; );&lt;br /&gt;
	} else {&lt;br /&gt;
		$msg = JText::_( &#039;Action executed&#039; );&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	$this-&amp;gt;setRedirect( &#039;index.php?option=&amp;lt;componentname&amp;gt;&#039;, $msg );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A controller takes care of all tasks for that dedicated controller. After completing a resulting task the module will return to the main administration entrance point for that component, the main controller with the default view. Activating tasks enforce a new view with a form to display after first defining it.&lt;br /&gt;
&lt;br /&gt;
The explicit definition of the form within a view might raise some eyebrows but our examples are too simple. For the general understanding and consistency this field should mostly be &#039;&#039;default&#039;&#039;. In complex views multiple forms could be defined within one view.&lt;br /&gt;
&lt;br /&gt;
==== Models ====&lt;br /&gt;
The Controllers interact with their equally named Model counter part. In the frontend view the Model was only used to retrieve data. The backend has more controllers and thus also more model files. The backend model files not only are responsible for delivering data to the viewer but also take care of tasks initiated from the controller. A good model contains all actions required to manage a single table in the database.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/relation.php&lt;br /&gt;
&lt;br /&gt;
==== Views ====&lt;br /&gt;
Separate views are of course also required. For views and subsequent forms no forced naming conventions are required (linking to views is taken care of in the controller). In the following listing the Administrative tasks are identified as a subset for the different views. This choice is totally random and maybe even non-logical but that doesn&#039;t matter for the explanation. Just for example purposes I added also a different view, a delete view, that could be used for all the deletes for all administrative tasks asking an &amp;quot;Are you sure&amp;quot; display.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/&amp;lt;componentname&amp;gt;/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/users/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/books/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/relation/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;amp;nbsp;&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/delete/view.html.php    + .../tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: In general it is good practice to maintain one form per view because the view.html.php still has to deliver the content. With some basic logic you can enable, disable certain content but if this logic is becoming too complex start considering splitting up the view. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Sharing template parts amongst the different views (for uniform layouting of headers and titles of your component) can be done using the PHP &amp;lt;code&amp;gt;include / require;&amp;lt;/code&amp;gt;. There is one slight problem ... how to make the logical reference? In my modules I have a collector bin for general to use sniplets. Because it involved the views and forms I put this general bin in the views directory. The variable $pathToGeneralView needs to be defined somewhere in the first lines of your file and you have to make sure that the logical reference path is correct (the &#039;..&#039;s). In the following example the files marked with a &#039;*&#039; use the following code:&lt;br /&gt;
&lt;br /&gt;
 ./com_compname/views/general/navigate.header.php  &amp;lt;-- sniplet code for the header&lt;br /&gt;
 ./com_compname/views/general/navigate.footer.php  &amp;lt;-- sniplet code for the footer&lt;br /&gt;
 ./com_compname/views/mngtable1/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable1/tmpl/default.php *&lt;br /&gt;
 ./com_compname/views/mngtable2/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable2/tmpl/default.php *&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER[&#039;SCRIPT_NAME&#039;]));&lt;br /&gt;
$pathToGeneralView = str_replace(dirname($_SERVER[&#039;SCRIPT_NAME&#039;]),&#039;.&#039;,$pathToGeneralView );&lt;br /&gt;
$pathToGeneralView = $pathToGeneralView . &amp;quot;/../../general/&amp;quot;;  &amp;lt;-- returning path from current position. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.header.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;P&amp;gt;Do something    &lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.footer.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Giving the forms logical instead of the &#039;&#039;default&#039;&#039; naming is of course handy when having a lot of different views. Having also that much &#039;&#039;default&#039;&#039; forms could make you easily loose oversight. On the other hand the view.html.php can not be renamed and you are always forced to look at the directory name for the view name you are working in.&lt;br /&gt;
&lt;br /&gt;
=== Essential Interaction Parameters ===&lt;br /&gt;
Everything is in place:&lt;br /&gt;
* main and dedicated controllers;&lt;br /&gt;
* main and dedicated modules;&lt;br /&gt;
* different views and their forms.&lt;br /&gt;
&lt;br /&gt;
Just one big question remains: &#039;&#039;&#039;How to use them&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Three parameters are mandatory for letting Joomla! do its job:&lt;br /&gt;
* option&lt;br /&gt;
* controller&lt;br /&gt;
* task&lt;br /&gt;
&lt;br /&gt;
These three parameters are almost self explaining ;). The &#039;&#039;option&#039;&#039; part when developing a component is easy, always assign your component name to it. For component development consider this one as a constant, of course the Joomla! engine has more options than only components.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;controller&#039;&#039; and &#039;&#039;task&#039;&#039; parameters can be manipulated within your component anyway you want it to. &lt;br /&gt;
&lt;br /&gt;
==== How it all works together ====&lt;br /&gt;
Looking at the simplified MVC picture Joomla! the logical flow of interaction goes the following way:&lt;br /&gt;
# What is my entrance point? &lt;br /&gt;
#*The Joomla! engine discovers a logged in administrator and sets the entrance point to &amp;lt;root&amp;gt;/administrator/index.php otherwise it wil go to the &amp;lt;root&amp;gt;/index.php entrance.&lt;br /&gt;
# What option is requested? &lt;br /&gt;
#*The Joomla! engine reads the option variable and discovers that a component named &amp;lt;componentname&amp;gt; is requested. The entrance point becomes: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
# Is there need to access a dedicated controller? &lt;br /&gt;
#* The Joomla! engine reads the controller variable and discovers that a dedicated controller is required: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/controllers/&amp;lt;dedicatedcontroller&amp;gt;.php&lt;br /&gt;
# Is there a task that needs to be addressed? &lt;br /&gt;
#* The identified controller is handed the task value as parameter. &lt;br /&gt;
# The Model is derived from the controller and instantiated.&lt;br /&gt;
# The View and Form are set in the controller and initiated to become active.&lt;br /&gt;
&lt;br /&gt;
=== How to add interaction ===&lt;br /&gt;
Within HTML there are two common ways to interact with Joomla!:&lt;br /&gt;
# reference to a link&lt;br /&gt;
# form submission post / get&lt;br /&gt;
&lt;br /&gt;
==== Link reference for the Joomla! engine ====&lt;br /&gt;
Again the &#039;&#039;&#039;activating tasks&#039;&#039;&#039; and &#039;&#039;&#039;resulting task&#039;&#039;&#039; definitions drop by. Most activating tasks are initiated by a link. In case of the Library example the site section overview could be copied to the admin section. This default view will now be extended and every cell will become a link for editing the specific database element.&lt;br /&gt;
&lt;br /&gt;
Using the Library example, the template PHP code without looping control will contain the following code:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=users&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idu );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=books&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idb );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;title&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=relation&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idr );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;date&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within each clickable field the three mandatory parameters to manipulate MVC can be identified. In addation there is one user parameter for handling the correct index in the controller task (cid). These parameter are separated by &#039;&amp;amp;&#039;. Do not use spaces in your variables this might screw-up parameter handling in certain browsers. After looping all text entries will be clickable and trigger the corresponding controller with the correct row id in the associated table.&lt;br /&gt;
&lt;br /&gt;
 [Alice} | [One flew over ...] | [12 aug 2009]&lt;br /&gt;
 [Alice] | [Celeb talk]        | [12 aug 2009]&lt;br /&gt;
 [Mark]  | [Joomla!]           | [15 aug 2009]&lt;br /&gt;
&lt;br /&gt;
==== Posting Form Data to the Joomla! Engine ====&lt;br /&gt;
After being initiated by an activating task, an input form view might be the result. The sniplet code below could be the result of clicking the first cell of the default component view that is clicked for editing ([Alice]:cid=3). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; id=&amp;quot;username&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;name;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;SubmitButton&amp;quot; value=&amp;quot;Save&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_library&amp;quot; /&amp;gt;                  // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;                    // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;save&amp;quot; /&amp;gt;                           // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;   // &amp;lt;-- user parameter, index in database for [Alice]&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The three Joomla! mandatory parameters are placed as hidden in the form. Hidden parameters are not shown in any way but will be added to the posting data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tip&#039;&#039;: when debugging this form, replace in the form tag &amp;lt;code&amp;gt;method=&amp;quot;post&amp;quot;&amp;lt;/code&amp;gt; temporarily with &amp;lt;code&amp;gt;method=&amp;quot;get&amp;quot;&amp;lt;/code&amp;gt;. All posted parameters will be shown in the URL of your browser. If the module is working undo this change. For one reason it looks sharper without all the parameters being shown in the URL and you avoid motivating people to manipulate the browser URL themselves. Of course one can look at the source code but using &#039;&#039;Post&#039;&#039; instead of &#039;&#039;Get&#039;&#039;, but this eliminates the first 90% of the earth population. The other reason is more technical and simply explained the method=&amp;quot;post&amp;quot; can contain more (complex) data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Remark&#039;&#039;: In some developed modules you may notice that developers have also added the &#039;&#039;view&#039;&#039; parameter. This is bad programming whilst the controller(s) should take care of the &#039;&#039;view&#039;&#039; and the &#039;&#039;form&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
The use of the three mandatory parameters and the different access points are clarified. Let&#039;s do something with this knowledge and extend the Hello component to the administrative section in the succeeding articles of this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15854</id>
		<title>J1.5:Developing a MVC Component/Creating an Administrator Interface</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15854"/>
		<updated>2009-10-09T19:42:59Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Link reference for the Joomla! engine */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ambox&lt;br /&gt;
| type  = notice&lt;br /&gt;
| image = notice&lt;br /&gt;
| text  = This {{thingamabob}} has been divided into three sections, two new articles are added. Especially this page needs a review&lt;br /&gt;
&amp;lt;small&amp;gt;(August 2009)&amp;lt;/small&amp;gt;}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first three tutorials, we have developed a MVC component that retrieves its data from a table in the database. Currently, there is no way to add data to the database except to do it manually using another tool. In the next articles of this tutorial, we will develop an administrator section for our component which will make it possible to manage the entries in the database.&lt;br /&gt;
&lt;br /&gt;
This article, [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface | Part 4 - Creating an Administrator Interface ]], will be an article with no new source code for our Hello component but we will go into some basic details of the MVC pattern. In the frontend solution (site section) we have developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were taken by the hand to trust the default handling of the code. This is going to change in the Backend or Administration section of our Hello component.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The frontend is used for presenting the users with content and allowing certain logged in users to manipulate the content, the backend is responsible for administrating the website framework (structuring / managing / controlling / maintaining). This division between site-content and administration is a fundamental aspect of the Joomla! architecture.&lt;br /&gt;
&lt;br /&gt;
=== Entrance points ===&lt;br /&gt;
From the XML file of our frontend example it was already obvious that there would be an administration part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
  &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!--  Administration Menu Section --&amp;gt; &lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt; &lt;br /&gt;
  &amp;lt;!--  Administration Main File Copy Section --&amp;gt; &lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;/files&amp;gt;&lt;br /&gt;
  &amp;lt;/administration&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only the .sql files were of use and only during installation for our frontend view, the other two files have no content besides generating a blank page. Access your websites file system at your hosting provider (or on your own server) and browse through the directories after installing the frontend com_hello component. You may have noticed that our Hello component is to be found twice:&lt;br /&gt;
 &amp;lt;root&amp;gt;/components/com_hello&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/components/com_hello&lt;br /&gt;
&lt;br /&gt;
These two sub-directories link to the previously explained site-content and administration. Administrator interactions explicitly go via the administrator sub-directory, where guest or registered users will enter the default entrance on the root:&lt;br /&gt;
 &amp;lt;root&amp;gt;/index.php&lt;br /&gt;
Administrative users will have to log in, and after logging in they will enter your site via:&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/index.php&lt;br /&gt;
&lt;br /&gt;
With the different access points it is easy to grasp that with setting up the administrator section the naming conventions have no dependency with the site section. Whilst the MVC pattern is also applicable for the administrator section this implies that identical Controls, Views and Models naming can (and sometimes must) be used as in the site section.&lt;br /&gt;
&lt;br /&gt;
== MVC pattern interaction ==&lt;br /&gt;
[[image:MVC joomla.png|frameless|right]]In [[Developing a Model-View-Controller Component - Part 1]] the figure on the right was used to explain the focus of the first three parts of this &#039;&#039;Developing a Model-View-Controller Component tutorial&#039;&#039;. Now we will use this figure to explain how decisions are made on what is going to be displayed and how to manipulate this.&lt;br /&gt;
&lt;br /&gt;
=== Example roll-out ===&lt;br /&gt;
For explanation purposes an easy to grasp example will be used. A library has the main function of lending books to registered users. Simply laid out there are three tables:&lt;br /&gt;
* users&lt;br /&gt;
* books&lt;br /&gt;
* relation&lt;br /&gt;
&lt;br /&gt;
Lets keep it all very simple. The users are addressed by Id and Name. The books are identified by Id and Title and the relation contains both Ids and the date of lending.&lt;br /&gt;
&lt;br /&gt;
[[image:Library Example.png|400px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The example is carefully chosen and will help in explaining the Joomla! architecture in more detail. The administrative side of our Hello component is not even that complex with only one table to manage. After the explanation of this chapter it should be easy to follow the tutorial in the succeeding chapters&lt;br /&gt;
&lt;br /&gt;
=== Mapping a Joomla! MVC component from the example ===&lt;br /&gt;
In this example we will assume that administrative actions (add, edit, delete) are tasks that are to be performed by the administrator. For the frontend user only the view of the Relation table is interesting (&amp;quot;when do I have to bring back the books?&amp;quot;). This example shows the entire list and ignores all privacy stuff that could be taken care of by letting registered users only see their own books (&#039;&#039;Hint&#039;&#039;: &amp;lt;code&amp;gt;if ($user-&amp;gt;registered) {}&amp;lt;/code&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
Just like our frontend Hello component, for this library component only the default view is being used in the frontend. It lists the relational table, left joining the other two tables to obtain a human readable list of lend books. &lt;br /&gt;
 Alice | One flew over ... | 12 aug 2009&lt;br /&gt;
 Alice | Celeb talk        | 12 aug 2009&lt;br /&gt;
 Mark  | Joomla!           | 15 aug 2009&lt;br /&gt;
&lt;br /&gt;
With respect to the administration part it is important to understand that we have one default and three dedicated views, each controlling three tasks:&lt;br /&gt;
* &amp;lt;Component name default view&amp;gt;&lt;br /&gt;
* User administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Book administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Relation administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
&lt;br /&gt;
==== Controllers ====&lt;br /&gt;
The main controller of the admin section needs to differentiate between the different Adds, Changes or Deletes that are requested. This is taken care of by creating sub-controllers for each view for handling their specific tasks.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controller.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/relation.php&lt;br /&gt;
&lt;br /&gt;
The controller is an important part of the MVC pattern. Not only does it take care of the requested tasks, it is also the initiator of instantiating the model with the same name and it is responsible for setting the view and the desired form for that view. The controller really justifies its name. &lt;br /&gt;
&lt;br /&gt;
Within the controller it is good to make a difference between &#039;&#039;&#039;activating tasks&#039;&#039;&#039; (for example the edit selection from a menu) and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; (for example the result of an edit trigger is the posted data).&lt;br /&gt;
&lt;br /&gt;
Typical controller functions look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function &amp;lt;activating task&amp;gt;()  // &amp;lt;-- edit, add, delete &lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;default&#039;  );     // &amp;lt;-- The default form is named here but in complex &lt;br /&gt;
                                                  //     views multiple layouts might be needed.&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function &amp;lt;resulting task&amp;gt;()  // &amp;lt;-- save, remove&lt;br /&gt;
{&lt;br /&gt;
	$model = $this-&amp;gt;getModel(&#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039;);&lt;br /&gt;
	if(!$model-&amp;gt;action() ) {    // &amp;lt;-- action could be delete() or store()&lt;br /&gt;
		$msg = JText::_( &#039;Error: Could not perform action&#039; );&lt;br /&gt;
	} else {&lt;br /&gt;
		$msg = JText::_( &#039;Action executed&#039; );&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	$this-&amp;gt;setRedirect( &#039;index.php?option=&amp;lt;componentname&amp;gt;&#039;, $msg );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A controller takes care of all tasks for that dedicated controller. After completing a resulting task the module will return to the main administration entrance point for that component, the main controller with the default view. Activating tasks enforce a new view with a form to display after first defining it.&lt;br /&gt;
&lt;br /&gt;
The explicit definition of the form within a view might raise some eyebrows but our examples are too simple. For the general understanding and consistency this field should mostly be &#039;&#039;default&#039;&#039;. In complex views multiple forms could be defined within one view.&lt;br /&gt;
&lt;br /&gt;
==== Models ====&lt;br /&gt;
The Controllers interact with their equally named Model counter part. In the frontend view the Model was only used to retrieve data. The backend has more controllers and thus also more model files. The backend model files not only are responsible for delivering data to the viewer but also take care of tasks initiated from the controller. A good model contains all actions required to manage a single table in the database.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/relation.php&lt;br /&gt;
&lt;br /&gt;
==== Views ====&lt;br /&gt;
Separate views are of course also required. For views and subsequent forms no forced naming conventions are required (linking to views is taken care of in the controller). In the following listing the Administrative tasks are identified as a subset for the different views. This choice is totally random and maybe even non-logical but that doesn&#039;t matter for the explanation. Just for example purposes I added also a different view, a delete view, that could be used for all the deletes for all administrative tasks asking an &amp;quot;Are you sure&amp;quot; display.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/&amp;lt;componentname&amp;gt;/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/users/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/books/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/relation/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;amp;nbsp;&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/delete/view.html.php    + .../tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: In general it is good practice to maintain one form per view because the view.html.php still has to deliver the content. With some basic logic you can enable, disable certain content but if this logic is becoming too complex start considering splitting up the view. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Sharing template parts amongst the different views (for uniform layouting of headers and titles of your component) can be done using the PHP &amp;lt;code&amp;gt;include / require;&amp;lt;/code&amp;gt;. There is one slight problem ... how to make the logical reference? In my modules I have a collector bin for general to use sniplets. Because it involved the views and forms I put this general bin in the views directory. The variable $pathToGeneralView needs to be defined somewhere in the first lines of your file and you have to make sure that the logical reference path is correct (the &#039;..&#039;s). In the following example the files marked with a &#039;*&#039; use the following code:&lt;br /&gt;
&lt;br /&gt;
 ./com_compname/views/general/navigate.header.php  &amp;lt;-- sniplet code for the header&lt;br /&gt;
 ./com_compname/views/general/navigate.footer.php  &amp;lt;-- sniplet code for the footer&lt;br /&gt;
 ./com_compname/views/mngtable1/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable1/tmpl/default.php *&lt;br /&gt;
 ./com_compname/views/mngtable2/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable2/tmpl/default.php *&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER[&#039;SCRIPT_NAME&#039;]));&lt;br /&gt;
$pathToGeneralView = str_replace(dirname($_SERVER[&#039;SCRIPT_NAME&#039;]),&#039;.&#039;,$pathToGeneralView );&lt;br /&gt;
$pathToGeneralView = $pathToGeneralView . &amp;quot;/../../general/&amp;quot;;  &amp;lt;-- returning path from current position. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.header.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;P&amp;gt;Do something    &lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.footer.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Giving the forms logical instead of the &#039;&#039;default&#039;&#039; naming is of course handy when having a lot of different views. Having also that much &#039;&#039;default&#039;&#039; forms could make you easily loose oversight. On the other hand the view.html.php can not be renamed and you are always forced to look at the directory name for the view name you are working in.&lt;br /&gt;
&lt;br /&gt;
=== Essential Interaction Parameters ===&lt;br /&gt;
Everything is in place:&lt;br /&gt;
* main and dedicated controllers;&lt;br /&gt;
* main and dedicated modules;&lt;br /&gt;
* different views and their forms.&lt;br /&gt;
&lt;br /&gt;
Just one big question remains: &#039;&#039;&#039;How to use them&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Three parameters are mandatory for letting Joomla! do its job:&lt;br /&gt;
* option&lt;br /&gt;
* controller&lt;br /&gt;
* task&lt;br /&gt;
&lt;br /&gt;
These three parameters are almost self explaining ;). The &#039;&#039;option&#039;&#039; part when developing a component is easy, always assign your component name to it. For component development consider this one as a constant, of course the Joomla! engine has more options than only components.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;controller&#039;&#039; and &#039;&#039;task&#039;&#039; parameters can be manipulated within your component anyway you want it to. &lt;br /&gt;
&lt;br /&gt;
==== How it all works together ====&lt;br /&gt;
Looking at the simplified MVC picture Joomla! the logical flow of interaction goes the following way:&lt;br /&gt;
# What is my entrance point? &lt;br /&gt;
#*The Joomla! engine discovers a logged in administrator and sets the entrance point to &amp;lt;root&amp;gt;/administrator/index.php otherwise it wil go to the &amp;lt;root&amp;gt;/index.php entrance.&lt;br /&gt;
# What option is requested? &lt;br /&gt;
#*The Joomla! engine reads the option variable and discovers that a component named &amp;lt;componentname&amp;gt; is requested. The entrance point becomes: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
# Is there need to access a dedicated controller? &lt;br /&gt;
#* The Joomla! engine reads the controller variable and discovers that a dedicated controller is required: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/controllers/&amp;lt;dedicatedcontroller&amp;gt;.php&lt;br /&gt;
# Is there a task that needs to be addressed? &lt;br /&gt;
#* The identified controller is handed the task value as parameter. &lt;br /&gt;
# The Model is derived from the controller and instantiated.&lt;br /&gt;
# The View and Form are set in the controller and initiated to become active.&lt;br /&gt;
&lt;br /&gt;
=== How to add interaction ===&lt;br /&gt;
Within HTML there are two common ways to interact with Joomla!:&lt;br /&gt;
# reference to a link&lt;br /&gt;
# form submission post / get&lt;br /&gt;
&lt;br /&gt;
==== Link reference for the Joomla! engine ====&lt;br /&gt;
Again the &#039;&#039;&#039;activating tasks&#039;&#039;&#039; and &#039;&#039;&#039;resulting task&#039;&#039;&#039; definitions drop by. Most activating tasks are initiated by a link. In case of the Library example the site section overview could be copied to the admin section. This default view will now be extended and every cell will become a link for editing the specific database element.&lt;br /&gt;
&lt;br /&gt;
Using the Library example, the template PHP code without looping control will contain following code:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=users&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idu );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=books&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idb );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;title&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=relation&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idr );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;date&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within each clickable field the three mandatory parameters to manipulate MVC can be identified. In addation there is one user parameter for handling the correct index in the controller task (cid). These parameter are separated by &#039;&amp;amp;&#039;. Do not use spaces in your variables this might screw-up parameter handling in certain browsers. After looping all text entries will be clickable and trigger the corresponding controller with the correct row id in the associated table.&lt;br /&gt;
&lt;br /&gt;
 [Alice} | [One flew over ...] | [12 aug 2009]&lt;br /&gt;
 [Alice] | [Celeb talk]        | [12 aug 2009]&lt;br /&gt;
 [Mark]  | [Joomla!]           | [15 aug 2009]&lt;br /&gt;
&lt;br /&gt;
==== Posting Form Data to the Joomla! Engine ====&lt;br /&gt;
After being initiated by an activating task, an input form view might be the result. The sniplet code below could be the result of clicking the first cell of the default component view that is clicked for editing ([Alice]:cid=3). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; id=&amp;quot;username&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;name;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;SubmitButton&amp;quot; value=&amp;quot;Save&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_library&amp;quot; /&amp;gt;                  // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;                    // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;save&amp;quot; /&amp;gt;                           // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;   // &amp;lt;-- user parameter, index in database for [Alice]&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The three Joomla! mandatory parameters are placed as hidden in the form. Hidden parameters are not shown in any way but will be added to the posting data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tip&#039;&#039;: when debugging this form, replace in the form tag &amp;lt;code&amp;gt;method=&amp;quot;post&amp;quot;&amp;lt;/code&amp;gt; temporarily with &amp;lt;code&amp;gt;method=&amp;quot;get&amp;quot;&amp;lt;/code&amp;gt;. All posted parameters will be shown in the URL of your browser. If the module is working undo this change. For one reason it looks sharper without all the parameters being shown in the URL and you avoid motivating people to manipulate the browser URL themselves. Of course one can look at the source code but using &#039;&#039;Post&#039;&#039; instead of &#039;&#039;Get&#039;&#039;, but this eliminates the first 90% of the earth population. The other reason is more technical and simply explained the method=&amp;quot;post&amp;quot; can contain more (complex) data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Remark&#039;&#039;: In some developed modules you may notice that developers have also added the &#039;&#039;view&#039;&#039; parameter. This is bad programming whilst the controller(s) should take care of the &#039;&#039;view&#039;&#039; and the &#039;&#039;form&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
The use of the three mandatory parameters and the different access points are clarified. Let&#039;s do something with this knowledge and extend the Hello component to the administrative section in the succeeding articles of this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15853</id>
		<title>J1.5:Developing a MVC Component/Creating an Administrator Interface</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Creating_an_Administrator_Interface&amp;diff=15853"/>
		<updated>2009-10-09T18:23:34Z</updated>

		<summary type="html">&lt;p&gt;Memberclicks: /* Mapping the example to a new to develop Joomla! component */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ambox&lt;br /&gt;
| type  = notice&lt;br /&gt;
| image = notice&lt;br /&gt;
| text  = This {{thingamabob}} has been divided into three sections, two new articles are added. Especially this page needs a review&lt;br /&gt;
&amp;lt;small&amp;gt;(August 2009)&amp;lt;/small&amp;gt;}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first three tutorials, we have developed a MVC component that retrieves its data from a table in the database. Currently, there is no way to add data to the database except to do it manually using another tool. In the next articles of this tutorial, we will develop an administrator section for our component which will make it possible to manage the entries in the database.&lt;br /&gt;
&lt;br /&gt;
This article, [[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface | Part 4 - Creating an Administrator Interface ]], will be an article with no new source code for our Hello component but we will go into some basic details of the MVC pattern. In the frontend solution (site section) we have developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were taken by the hand to trust the default handling of the code. This is going to change in the Backend or Administration section of our Hello component.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The frontend is used for presenting the users with content and allowing certain logged in users to manipulate the content, the backend is responsible for administrating the website framework (structuring / managing / controlling / maintaining). This division between site-content and administration is a fundamental aspect of the Joomla! architecture.&lt;br /&gt;
&lt;br /&gt;
=== Entrance points ===&lt;br /&gt;
From the XML file of our frontend example it was already obvious that there would be an administration part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
  &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!--  Administration Menu Section --&amp;gt; &lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt; &lt;br /&gt;
  &amp;lt;!--  Administration Main File Copy Section --&amp;gt; &lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt; &lt;br /&gt;
  &amp;lt;/files&amp;gt;&lt;br /&gt;
  &amp;lt;/administration&amp;gt;&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only the .sql files were of use and only during installation for our frontend view, the other two files have no content besides generating a blank page. Access your websites file system at your hosting provider (or on your own server) and browse through the directories after installing the frontend com_hello component. You may have noticed that our Hello component is to be found twice:&lt;br /&gt;
 &amp;lt;root&amp;gt;/components/com_hello&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/components/com_hello&lt;br /&gt;
&lt;br /&gt;
These two sub-directories link to the previously explained site-content and administration. Administrator interactions explicitly go via the administrator sub-directory, where guest or registered users will enter the default entrance on the root:&lt;br /&gt;
 &amp;lt;root&amp;gt;/index.php&lt;br /&gt;
Administrative users will have to log in, and after logging in they will enter your site via:&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/index.php&lt;br /&gt;
&lt;br /&gt;
With the different access points it is easy to grasp that with setting up the administrator section the naming conventions have no dependency with the site section. Whilst the MVC pattern is also applicable for the administrator section this implies that identical Controls, Views and Models naming can (and sometimes must) be used as in the site section.&lt;br /&gt;
&lt;br /&gt;
== MVC pattern interaction ==&lt;br /&gt;
[[image:MVC joomla.png|frameless|right]]In [[Developing a Model-View-Controller Component - Part 1]] the figure on the right was used to explain the focus of the first three parts of this &#039;&#039;Developing a Model-View-Controller Component tutorial&#039;&#039;. Now we will use this figure to explain how decisions are made on what is going to be displayed and how to manipulate this.&lt;br /&gt;
&lt;br /&gt;
=== Example roll-out ===&lt;br /&gt;
For explanation purposes an easy to grasp example will be used. A library has the main function of lending books to registered users. Simply laid out there are three tables:&lt;br /&gt;
* users&lt;br /&gt;
* books&lt;br /&gt;
* relation&lt;br /&gt;
&lt;br /&gt;
Lets keep it all very simple. The users are addressed by Id and Name. The books are identified by Id and Title and the relation contains both Ids and the date of lending.&lt;br /&gt;
&lt;br /&gt;
[[image:Library Example.png|400px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The example is carefully chosen and will help in explaining the Joomla! architecture in more detail. The administrative side of our Hello component is not even that complex with only one table to manage. After the explanation of this chapter it should be easy to follow the tutorial in the succeeding chapters&lt;br /&gt;
&lt;br /&gt;
=== Mapping a Joomla! MVC component from the example ===&lt;br /&gt;
In this example we will assume that administrative actions (add, edit, delete) are tasks that are to be performed by the administrator. For the frontend user only the view of the Relation table is interesting (&amp;quot;when do I have to bring back the books?&amp;quot;). This example shows the entire list and ignores all privacy stuff that could be taken care of by letting registered users only see their own books (&#039;&#039;Hint&#039;&#039;: &amp;lt;code&amp;gt;if ($user-&amp;gt;registered) {}&amp;lt;/code&amp;gt; ).&lt;br /&gt;
&lt;br /&gt;
Just like our frontend Hello component, for this library component only the default view is being used in the frontend. It lists the relational table, left joining the other two tables to obtain a human readable list of lend books. &lt;br /&gt;
 Alice | One flew over ... | 12 aug 2009&lt;br /&gt;
 Alice | Celeb talk        | 12 aug 2009&lt;br /&gt;
 Mark  | Joomla!           | 15 aug 2009&lt;br /&gt;
&lt;br /&gt;
With respect to the administration part it is important to understand that we have one default and three dedicated views, each controlling three tasks:&lt;br /&gt;
* &amp;lt;Component name default view&amp;gt;&lt;br /&gt;
* User administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Book administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
* Relation administration&lt;br /&gt;
** Add&lt;br /&gt;
** Change&lt;br /&gt;
** Delete&lt;br /&gt;
&lt;br /&gt;
==== Controllers ====&lt;br /&gt;
The main controller of the admin section needs to differentiate between the different Adds, Changes or Deletes that are requested. This is taken care of by creating sub-controllers for each view for handling their specific tasks.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controller.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/controllers/relation.php&lt;br /&gt;
&lt;br /&gt;
The controller is an important part of the MVC pattern. Not only does it take care of the requested tasks, it is also the initiator of instantiating the model with the same name and it is responsible for setting the view and the desired form for that view. The controller really justifies its name. &lt;br /&gt;
&lt;br /&gt;
Within the controller it is good to make a difference between &#039;&#039;&#039;activating tasks&#039;&#039;&#039; (for example the edit selection from a menu) and &#039;&#039;&#039;resulting tasks&#039;&#039;&#039; (for example the result of an edit trigger is the posted data).&lt;br /&gt;
&lt;br /&gt;
Typical controller functions look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function &amp;lt;activating task&amp;gt;()  // &amp;lt;-- edit, add, delete &lt;br /&gt;
{&lt;br /&gt;
    JRequest::setVar( &#039;view&#039;, &#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039; );&lt;br /&gt;
    JRequest::setVar( &#039;layout&#039;, &#039;default&#039;  );     // &amp;lt;-- The default form is named here but in complex &lt;br /&gt;
                                                  //     views multiple layouts might be needed.&lt;br /&gt;
    parent::display();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function &amp;lt;resulting task&amp;gt;()  // &amp;lt;-- save, remove&lt;br /&gt;
{&lt;br /&gt;
	$model = $this-&amp;gt;getModel(&#039;[&amp;lt;componentname&amp;gt; | users | books | relation ]&#039;);&lt;br /&gt;
	if(!$model-&amp;gt;action() ) {    // &amp;lt;-- action could be delete() or store()&lt;br /&gt;
		$msg = JText::_( &#039;Error: Could not perform action&#039; );&lt;br /&gt;
	} else {&lt;br /&gt;
		$msg = JText::_( &#039;Action executed&#039; );&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	$this-&amp;gt;setRedirect( &#039;index.php?option=&amp;lt;componentname&amp;gt;&#039;, $msg );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A controller takes care of all tasks for that dedicated controller. After completing a resulting task the module will return to the main administration entrance point for that component, the main controller with the default view. Activating tasks enforce a new view with a form to display after first defining it.&lt;br /&gt;
&lt;br /&gt;
The explicit definition of the form within a view might raise some eyebrows but our examples are too simple. For the general understanding and consistency this field should mostly be &#039;&#039;default&#039;&#039;. In complex views multiple forms could be defined within one view.&lt;br /&gt;
&lt;br /&gt;
==== Models ====&lt;br /&gt;
The Controllers interact with their equally named Model counter part. In the frontend view the Model was only used to retrieve data. The backend has more controllers and thus also more model files. The backend model files not only are responsible for delivering data to the viewer but also take care of tasks initiated from the controller. A good model contains all actions required to manage a single table in the database.&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/users.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/books.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/models/relation.php&lt;br /&gt;
&lt;br /&gt;
==== Views ====&lt;br /&gt;
Separate views are of course also required. For views and subsequent forms no forced naming conventions are required (linking to views is taken care of in the controller). In the following listing the Administrative tasks are identified as a subset for the different views. This choice is totally random and maybe even non-logical but that doesn&#039;t matter for the explanation. Just for example purposes I added also a different view, a delete view, that could be used for all the deletes for all administrative tasks asking an &amp;quot;Are you sure&amp;quot; display.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/&amp;lt;componentname&amp;gt;/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/users/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/books/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/relation/view.html.php    + .../tmpl/default.php&lt;br /&gt;
 &amp;amp;nbsp;&lt;br /&gt;
 &amp;lt;root&amp;gt;/administrator/views/delete/view.html.php    + .../tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: In general it is good practice to maintain one form per view because the view.html.php still has to deliver the content. With some basic logic you can enable, disable certain content but if this logic is becoming too complex start considering splitting up the view. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Sharing template parts amongst the different views (for uniform layouting of headers and titles of your component) can be done using the PHP &amp;lt;code&amp;gt;include / require;&amp;lt;/code&amp;gt;. There is one slight problem ... how to make the logical reference? In my modules I have a collector bin for general to use sniplets. Because it involved the views and forms I put this general bin in the views directory. The variable $pathToGeneralView needs to be defined somewhere in the first lines of your file and you have to make sure that the logical reference path is correct (the &#039;..&#039;s). In the following example the files marked with a &#039;*&#039; use the following code:&lt;br /&gt;
&lt;br /&gt;
 ./com_compname/views/general/navigate.header.php  &amp;lt;-- sniplet code for the header&lt;br /&gt;
 ./com_compname/views/general/navigate.footer.php  &amp;lt;-- sniplet code for the footer&lt;br /&gt;
 ./com_compname/views/mngtable1/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable1/tmpl/default.php *&lt;br /&gt;
 ./com_compname/views/mngtable2/view.html.php&lt;br /&gt;
 ./com_compname/views/mngtable2/tmpl/default.php *&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER[&#039;SCRIPT_NAME&#039;]));&lt;br /&gt;
$pathToGeneralView = str_replace(dirname($_SERVER[&#039;SCRIPT_NAME&#039;]),&#039;.&#039;,$pathToGeneralView );&lt;br /&gt;
$pathToGeneralView = $pathToGeneralView . &amp;quot;/../../general/&amp;quot;;  &amp;lt;-- returning path from current position. &lt;br /&gt;
...&lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.header.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;P&amp;gt;Do something    &lt;br /&gt;
&amp;lt;?php require_once $pathToGeneralView . &#039;navigation.footer.php&#039;; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note&#039;&#039;: Giving the forms logical instead of the &#039;&#039;default&#039;&#039; naming is of course handy when having a lot of different views. Having also that much &#039;&#039;default&#039;&#039; forms could make you easily loose oversight. On the other hand the view.html.php can not be renamed and you are always forced to look at the directory name for the view name you are working in.&lt;br /&gt;
&lt;br /&gt;
=== Essential Interaction Parameters ===&lt;br /&gt;
Everything is in place:&lt;br /&gt;
* main and dedicated controllers;&lt;br /&gt;
* main and dedicated modules;&lt;br /&gt;
* different views and their forms.&lt;br /&gt;
&lt;br /&gt;
Just one big question remains: &#039;&#039;&#039;How to use them&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
Three parameters are mandatory for letting Joomla! do its job:&lt;br /&gt;
* option&lt;br /&gt;
* controller&lt;br /&gt;
* task&lt;br /&gt;
&lt;br /&gt;
These three parameters are almost self explaining ;). The &#039;&#039;option&#039;&#039; part when developing a component is easy, always assign your component name to it. For component development consider this one as a constant, of course the Joomla! engine has more options than only components.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;controller&#039;&#039; and &#039;&#039;task&#039;&#039; parameters can be manipulated within your component anyway you want it to. &lt;br /&gt;
&lt;br /&gt;
==== How it all works together ====&lt;br /&gt;
Looking at the simplified MVC picture Joomla! the logical flow of interaction goes the following way:&lt;br /&gt;
# What is my entrance point? &lt;br /&gt;
#*The Joomla! engine discovers a logged in administrator and sets the entrance point to &amp;lt;root&amp;gt;/administrator/index.php otherwise it wil go to the &amp;lt;root&amp;gt;/index.php entrance.&lt;br /&gt;
# What option is requested? &lt;br /&gt;
#*The Joomla! engine reads the option variable and discovers that a component named &amp;lt;componentname&amp;gt; is requested. The entrance point becomes: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/&amp;lt;componentname&amp;gt;.php&lt;br /&gt;
# Is there need to access a dedicated controller? &lt;br /&gt;
#* The Joomla! engine reads the controller variable and discovers that a dedicated controller is required: &amp;lt;root&amp;gt;/administrator/modules/com_&amp;lt;componentname&amp;gt;/controllers/&amp;lt;dedicatedcontroller&amp;gt;.php&lt;br /&gt;
# Is there a task that needs to be addressed? &lt;br /&gt;
#* The identified controller is handed the task value as parameter. &lt;br /&gt;
# The Model is derived from the controller and instantiated.&lt;br /&gt;
# The View and Form are set in the controller and initiated to become active.&lt;br /&gt;
&lt;br /&gt;
=== How to add interaction ===&lt;br /&gt;
Within HTML there are two common ways to interact with Joomla!:&lt;br /&gt;
# reference to a link&lt;br /&gt;
# form submission post / get&lt;br /&gt;
&lt;br /&gt;
==== Link reference for the Joomla! engine ====&lt;br /&gt;
Again the &#039;&#039;&#039;activating tasks&#039;&#039;&#039; and &#039;&#039;&#039;resulting task&#039;&#039;&#039; definitions drop by. Most activating tasks are initiated by a link. In case of the Library example the site section overview could be copied to the admin section. This default view will now be extended and every cell will become become a link for editing the specific database element.&lt;br /&gt;
&lt;br /&gt;
Using the Library example, the template PHP code without looping control will contain following code:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=users&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idu );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=books&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idb );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;title&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
$link = JRoute::_( &#039;index.php?option=com_library&amp;amp;controller=relation&amp;amp;task=edit&amp;amp;cid=&#039;. $row-&amp;gt;idr );&lt;br /&gt;
echo &amp;quot;&amp;lt;td&amp;gt;&amp;lt;a href=\&amp;quot;&amp;quot;.$link.&amp;quot;\&amp;quot;&amp;gt;$row-&amp;gt;date&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within each clickable field the three mandatory parameters to manipulate MVC can be identified. In addation there is one user parameter for handling the correct index in the controller task (cid). These parameter are separated by &#039;&amp;amp;&#039;. Do not use spaces in your variables this might screw-up parameter handling in certain browsers. After looping all text entries will be clickable and trigger the corresponding controller with the correct row id in the associated table.&lt;br /&gt;
&lt;br /&gt;
 [Alice} | [One flew over ...] | [12 aug 2009]&lt;br /&gt;
 [Alice] | [Celeb talk]        | [12 aug 2009]&lt;br /&gt;
 [Mark]  | [Joomla!]           | [15 aug 2009]&lt;br /&gt;
&lt;br /&gt;
==== Posting Form Data to the Joomla! Engine ====&lt;br /&gt;
After being initiated by an activating task, an input form view might be the result. The sniplet code below could be the result of clicking the first cell of the default component view that is clicked for editing ([Alice]:cid=3). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; id=&amp;quot;username&amp;quot; size=&amp;quot;32&amp;quot; maxlength=&amp;quot;250&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;name;?&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;SubmitButton&amp;quot; value=&amp;quot;Save&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;option&amp;quot; value=&amp;quot;com_library&amp;quot; /&amp;gt;                  // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;controller&amp;quot; value=&amp;quot;hello&amp;quot; /&amp;gt;                    // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;task&amp;quot; value=&amp;quot;save&amp;quot; /&amp;gt;                           // &amp;lt;-- mandatory&lt;br /&gt;
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;id&amp;quot; value=&amp;quot;&amp;lt;?php echo $this-&amp;gt;user-&amp;gt;id; ?&amp;gt;&amp;quot; /&amp;gt;   // &amp;lt;-- user parameter, index in database for [Alice]&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The three Joomla! mandatory parameters are placed as hidden in the form. Hidden parameters are not shown in any way but will be added to the posting data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tip&#039;&#039;: when debugging this form, replace in the form tag &amp;lt;code&amp;gt;method=&amp;quot;post&amp;quot;&amp;lt;/code&amp;gt; temporarily with &amp;lt;code&amp;gt;method=&amp;quot;get&amp;quot;&amp;lt;/code&amp;gt;. All posted parameters will be shown in the URL of your browser. If the module is working undo this change. For one reason it looks sharper without all the parameters being shown in the URL and you avoid motivating people to manipulate the browser URL themselves. Of course one can look at the source code but using &#039;&#039;Post&#039;&#039; instead of &#039;&#039;Get&#039;&#039;, but this eliminates the first 90% of the earth population. The other reason is more technical and simply explained the method=&amp;quot;post&amp;quot; can contain more (complex) data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Remark&#039;&#039;: In some developed modules you may notice that developers have also added the &#039;&#039;view&#039;&#039; parameter. This is bad programming whilst the controller(s) should take care of the &#039;&#039;view&#039;&#039; and the &#039;&#039;form&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
The use of the three mandatory parameters and the different access points are clarified. Let&#039;s do something with this knowledge and extend the Hello component to the administrative section in the succeeding articles of this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
* jamesconroyuk&lt;/div&gt;</summary>
		<author><name>Memberclicks</name></author>
	</entry>
</feed>