<?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=Upendotech</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=Upendotech"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Upendotech"/>
	<updated>2026-06-27T05:27:18Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Basic_Backend_Framework&amp;diff=29721</id>
		<title>J1.5:Developing a MVC Component/Basic Backend Framework</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Basic_Backend_Framework&amp;diff=29721"/>
		<updated>2010-08-08T18:41:44Z</updated>

		<summary type="html">&lt;p&gt;Upendotech: /* Tutorial specific naming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
This article focuses on the entry page/article for the administrator. Whilst the MVC pattern is the same as for the frontend user, this chapter will rapidly go though all steps and setup the backend counter part in the admin section. This article will only focus on setting up the Basic Framework with a list of all the &#039;&#039;Hellos&#039;&#039; but without user interaction. The actual user interaction is added in the succeeding article [[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial specific naming ==&lt;br /&gt;
Within the next articles the explanation of this administrator section we will keep as close as possible to the component name. For the general overview, lists from the database, we will use &#039;&#039;Hellos&#039;&#039; as identification. The &#039;&#039;Hellos&#039;&#039; naming will be used for viewing and controlling multiple Hellos at once from the database. When selecting a single Hello for Editing or Adding we will use the singular &#039;&#039;Hello&#039;&#039; as naming for the Controller and View. This &#039;&#039;Admin Hello&#039;&#039; has no functional relation with the &#039;&#039;Site Hello&#039;&#039; (the only dependency is the database content, of course).&lt;br /&gt;
&lt;br /&gt;
Where parts 1,2 and 3 of the MVC explanation were working in the site directory tree of com_hello, part 5 and 6 will focus on the admin directory tree. Part 5 and 6 will not add or change files in the site directory tree. Look at the XML file in the attached example of the full com_hello implementation. The XML configuration file will help you with the exact location of the different files being used in this and the following chapter.&lt;br /&gt;
&lt;br /&gt;
== Creating the Basic Framework ==&lt;br /&gt;
&lt;br /&gt;
The basic framework of the administrator panel is very similar to the site portion. The main entry point for the administrator section of the component is hello.php. This file is identical to the hello.php file that was used in the site portion except the name of the controller it loads will be changed to HellosController. The default controller is also called controller.php and this file is identical to the default controller in the site portion, with the exception that the controller is named HellosController instead of HelloController. This difference is so that JController will by default load the hellos view, which will display a list of our greetings.&lt;br /&gt;
&lt;br /&gt;
Here is the listing for hello.php:&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;
 * @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;
&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
// Require the base controller&lt;br /&gt;
&lt;br /&gt;
require_once( JPATH_COMPONENT.DS.&#039;controller.php&#039; );&lt;br /&gt;
&lt;br /&gt;
// Require specific controller if requested&lt;br /&gt;
if($controller = JRequest::getWord(&#039;controller&#039;)) {&lt;br /&gt;
    $path = JPATH_COMPONENT.DS.&#039;controllers&#039;.DS.$controller.&#039;.php&#039;;&lt;br /&gt;
    if (file_exists($path)) {&lt;br /&gt;
        require_once $path;&lt;br /&gt;
    } else {&lt;br /&gt;
        $controller = &#039;&#039;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Create the controller&lt;br /&gt;
$classname    = &#039;HellosController&#039;.$controller;&lt;br /&gt;
$controller   = new $classname( );&lt;br /&gt;
&lt;br /&gt;
// Perform the Request task&lt;br /&gt;
$controller-&amp;gt;execute( JRequest::getVar( &#039;task&#039; ) );&lt;br /&gt;
&lt;br /&gt;
// Redirect if set by the controller&lt;br /&gt;
$controller-&amp;gt;redirect();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view and model that we will start with is the hellos view and the hellos model. We will start with the model.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos Model ====&lt;br /&gt;
&lt;br /&gt;
The Hellos Model will be very simple. The only operation that we currently need is the ability to retrieve the list of hellos from the database. This operation will be implemented in a method called getData().&lt;br /&gt;
&lt;br /&gt;
The JModel class has a built in protected method called _getList(). This method can be used to simplify the task of retrieving a list of records from the database. We simply need to pass it the query and it will return the list of records.&lt;br /&gt;
&lt;br /&gt;
At a later point in time, we might want to use our query from within another method. Therefore, we will create a private method called _buildQuery() which will return the query that will be passed to _getList(). This makes it easier to change the query as well since it is localized in one place.&lt;br /&gt;
&lt;br /&gt;
Therefore we need two methods in our class: getData() and _buildQuery().&lt;br /&gt;
&lt;br /&gt;
_buildQuery() simply returns the query. It looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source  lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Returns the query&lt;br /&gt;
 * @return string The query to be used to retrieve the rows from the database&lt;br /&gt;
 */&lt;br /&gt;
function _buildQuery()&lt;br /&gt;
{&lt;br /&gt;
    $query = &#039; SELECT * &#039;&lt;br /&gt;
           . &#039; FROM #__hello &#039;&lt;br /&gt;
    ;&lt;br /&gt;
&lt;br /&gt;
    return $query;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
getData() will obtain the query and retrieve the records from the database. Now it might happen that we need to retrieve this list of data twice in one page load. It would be a waste to have to query the database twice. Therefore, we will have this method store the data in a protected property so that on subsequent requests it can simply return the data it has already retrieved. This property will be called _data. (&#039;&#039;&amp;lt;-- Naming convention conflict. Private or Protected data should be preceded with a &#039;_&#039; but as this reference is returned to the view where this data is directly accessed, this data can only be considered as public.&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
Here is the getData() method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source  lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Retrieves the hello data&lt;br /&gt;
 * @return array Array of objects containing the data from the database&lt;br /&gt;
 */&lt;br /&gt;
function getData()&lt;br /&gt;
{&lt;br /&gt;
    // Lets load the data if it doesn&#039;t already exist&lt;br /&gt;
    if (empty( $this-&amp;gt;_data ))&lt;br /&gt;
    {&lt;br /&gt;
        $query = $this-&amp;gt;_buildQuery();&lt;br /&gt;
        $this-&amp;gt;_data = $this-&amp;gt;_getList( $query );&lt;br /&gt;
    }&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 completed model looks like:&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;
 * Hellos Model for Hello World Component&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;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die();&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.application.component.model&#039; );&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Hello Model&lt;br /&gt;
 *&lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 */&lt;br /&gt;
class HellosModelHellos extends JModel&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * Hellos data array&lt;br /&gt;
     *&lt;br /&gt;
     * @var array&lt;br /&gt;
     */&lt;br /&gt;
    var $_data;&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the query&lt;br /&gt;
     * @return string The query to be used to retrieve the rows from the database&lt;br /&gt;
     */&lt;br /&gt;
    function _buildQuery()&lt;br /&gt;
    {&lt;br /&gt;
        $query = &#039; SELECT * &#039;&lt;br /&gt;
            . &#039; FROM #__hello &#039;&lt;br /&gt;
        ;&lt;br /&gt;
        return $query;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Retrieves the hello data&lt;br /&gt;
     * @return array Array of objects containing the data from the database&lt;br /&gt;
     */&lt;br /&gt;
    function getData()&lt;br /&gt;
    {&lt;br /&gt;
        // Lets load the data if it doesn&#039;t already exist&lt;br /&gt;
        if (empty( $this-&amp;gt;_data ))&lt;br /&gt;
        {&lt;br /&gt;
            $query = $this-&amp;gt;_buildQuery();&lt;br /&gt;
            $this-&amp;gt;_data = $this-&amp;gt;_getList( $query );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $this-&amp;gt;_data;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file is saved as models/hellos.php.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos View ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a model to retrieve our data, we need to display it. This view will be fairly similar to the view from the site section as well.&lt;br /&gt;
&lt;br /&gt;
Just as our model was automatically instantiated in the site, so it is in the administrator. Methods that start with &amp;quot;get&amp;quot; [e.g. getData()] in the model can be accessed using the get() method of the JView class. So our view has three lines: one to retrieve the data from the model, one to push the data into the template, and one to invoke the display method to display the output. Thus we have:&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;
 * Hellos View for Hello World Component&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;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die();&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.application.component.view&#039; );&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Hellos View&lt;br /&gt;
 *&lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 */&lt;br /&gt;
class HellosViewHellos extends JView&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * Hellos view display method&lt;br /&gt;
     * @return void&lt;br /&gt;
     **/&lt;br /&gt;
    function display($tpl = null)&lt;br /&gt;
    {&lt;br /&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();&lt;br /&gt;
&lt;br /&gt;
        // Get data from the model&lt;br /&gt;
        $items =&amp;amp; $this-&amp;gt;get( &#039;Data&#039;);&lt;br /&gt;
&lt;br /&gt;
        $this-&amp;gt;assignRef( &#039;items&#039;, $items );&lt;br /&gt;
&lt;br /&gt;
        parent::display($tpl);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file is saved as views/hellos/view.html.php.&lt;br /&gt;
&lt;br /&gt;
Look carefully at the almost hidden differences compared to &#039;&#039;site&#039;&#039; example. The data is stored in a variable that is encapsulated within the model. Because the data amount is huge due to using the very handy _getList(), the need for returning a reference instead of a value is obvious. This is handled in:&lt;br /&gt;
 $items =&amp;amp; $this-&amp;gt;get( &#039;Data&#039;);&lt;br /&gt;
Looking again at this line and you will notice another difference with respect to the &#039;&#039;site&#039;&#039; view.html.php. The calling of the model function is done implicitly. The actual model function name is getData(). In the &#039;&#039;site&#039;&#039; example you had to call following two lines:&lt;br /&gt;
 $model =&amp;amp; $this-&amp;gt;getModel();&lt;br /&gt;
 $greeting = $model-&amp;gt;getData();&lt;br /&gt;
Both lines are now taken care of by calling: &amp;lt;code&amp;gt;$this-&amp;gt;get( &#039;Data&#039;);&amp;lt;/code&amp;gt;. Under the surface of this &amp;lt;code&amp;gt;get()&amp;lt;/code&amp;gt; the &#039;Data&#039; is prefixed with &#039;get&#039; so when using this function make sure the model functions are preceded with &#039;get&#039;. This function can also be used in the &#039;&#039;site&#039;&#039; section. Keeping the data in the model and accessing it by reference, via &amp;lt;code&amp;gt;get()&amp;lt;/code&amp;gt; methods, is the preferred way of getting data from the model.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos Template ====&lt;br /&gt;
&lt;br /&gt;
The template will take the data pushed into it from the view and produce the output. We will display our output in a simple table. While the frontend template was very simple, in the administrator we will need a minimal amount of extra logic to handle looping through the data.&lt;br /&gt;
&lt;br /&gt;
Here is our template:&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&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;
    foreach ($this-&amp;gt;items as &amp;amp;$row)&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 $row-&amp;gt;greeting; ?&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;
This template is saved as views/hellos/tmpl/default.php.&lt;br /&gt;
&lt;br /&gt;
You will notice that our output is enclosed in a form. Though this is not necessary now, it will be soon.&lt;br /&gt;
&lt;br /&gt;
We have now completed the basic part of the first view. We have added five files to the admin section of our component:&lt;br /&gt;
&lt;br /&gt;
* hello.php&lt;br /&gt;
* controller.php&lt;br /&gt;
* models/hellos.php&lt;br /&gt;
* views/hellos/view.html.php&lt;br /&gt;
* views/hellos/tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
You can now add these files to the XML install file and give it a try!&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
We have now implemented a basic framework for the backend admin component. A list where all of the Hellos are displayed. The next chapter will extend this framework and add user interaction / database manipulation.&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 full admin 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>Upendotech</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Basic_Backend_Framework&amp;diff=29720</id>
		<title>J1.5:Developing a MVC Component/Basic Backend Framework</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Basic_Backend_Framework&amp;diff=29720"/>
		<updated>2010-08-08T18:40:26Z</updated>

		<summary type="html">&lt;p&gt;Upendotech: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
This article focuses on the entry page/article for the administrator. Whilst the MVC pattern is the same as for the frontend user, this chapter will rapidly go though all steps and setup the backend counter part in the admin section. This article will only focus on setting up the Basic Framework with a list of all the &#039;&#039;Hellos&#039;&#039; but without user interaction. The actual user interaction is added in the succeeding article [[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]].&lt;br /&gt;
&lt;br /&gt;
== Tutorial specific naming ==&lt;br /&gt;
Within the next articles the explanation of this administrator section we will keep as close as possible to the component name. For the general overview, lists from the database, we will use &#039;&#039;Hellos&#039;&#039; as identification. The &#039;&#039;Hellos&#039;&#039; naming will be used for viewing and controlling multiple Hellos at once from the database. When selecting a single Hello for Editing or Adding we will use the singular &#039;&#039;Hello&#039;&#039; as naming for the Controller and View. This &#039;&#039;Admin Hello&#039;&#039; has no functional relation with the &#039;&#039;Site Hello&#039;&#039; (the only dependency is the database content, of cause).&lt;br /&gt;
&lt;br /&gt;
Where parts 1,2 and 3 of the MVC explanation were working in the site directory tree of com_hello, part 5 and 6 will focus on the admin directory tree. Part 5 and 6 will not add or change files in the site directory tree. Look at the XML file in the attached example of the full com_hello implementation. The XML configuration file will help you with the exact location of the different files being used in this and the following chapter.&lt;br /&gt;
&lt;br /&gt;
== Creating the Basic Framework ==&lt;br /&gt;
&lt;br /&gt;
The basic framework of the administrator panel is very similar to the site portion. The main entry point for the administrator section of the component is hello.php. This file is identical to the hello.php file that was used in the site portion except the name of the controller it loads will be changed to HellosController. The default controller is also called controller.php and this file is identical to the default controller in the site portion, with the exception that the controller is named HellosController instead of HelloController. This difference is so that JController will by default load the hellos view, which will display a list of our greetings.&lt;br /&gt;
&lt;br /&gt;
Here is the listing for hello.php:&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;
 * @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;
&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
// Require the base controller&lt;br /&gt;
&lt;br /&gt;
require_once( JPATH_COMPONENT.DS.&#039;controller.php&#039; );&lt;br /&gt;
&lt;br /&gt;
// Require specific controller if requested&lt;br /&gt;
if($controller = JRequest::getWord(&#039;controller&#039;)) {&lt;br /&gt;
    $path = JPATH_COMPONENT.DS.&#039;controllers&#039;.DS.$controller.&#039;.php&#039;;&lt;br /&gt;
    if (file_exists($path)) {&lt;br /&gt;
        require_once $path;&lt;br /&gt;
    } else {&lt;br /&gt;
        $controller = &#039;&#039;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Create the controller&lt;br /&gt;
$classname    = &#039;HellosController&#039;.$controller;&lt;br /&gt;
$controller   = new $classname( );&lt;br /&gt;
&lt;br /&gt;
// Perform the Request task&lt;br /&gt;
$controller-&amp;gt;execute( JRequest::getVar( &#039;task&#039; ) );&lt;br /&gt;
&lt;br /&gt;
// Redirect if set by the controller&lt;br /&gt;
$controller-&amp;gt;redirect();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view and model that we will start with is the hellos view and the hellos model. We will start with the model.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos Model ====&lt;br /&gt;
&lt;br /&gt;
The Hellos Model will be very simple. The only operation that we currently need is the ability to retrieve the list of hellos from the database. This operation will be implemented in a method called getData().&lt;br /&gt;
&lt;br /&gt;
The JModel class has a built in protected method called _getList(). This method can be used to simplify the task of retrieving a list of records from the database. We simply need to pass it the query and it will return the list of records.&lt;br /&gt;
&lt;br /&gt;
At a later point in time, we might want to use our query from within another method. Therefore, we will create a private method called _buildQuery() which will return the query that will be passed to _getList(). This makes it easier to change the query as well since it is localized in one place.&lt;br /&gt;
&lt;br /&gt;
Therefore we need two methods in our class: getData() and _buildQuery().&lt;br /&gt;
&lt;br /&gt;
_buildQuery() simply returns the query. It looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source  lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Returns the query&lt;br /&gt;
 * @return string The query to be used to retrieve the rows from the database&lt;br /&gt;
 */&lt;br /&gt;
function _buildQuery()&lt;br /&gt;
{&lt;br /&gt;
    $query = &#039; SELECT * &#039;&lt;br /&gt;
           . &#039; FROM #__hello &#039;&lt;br /&gt;
    ;&lt;br /&gt;
&lt;br /&gt;
    return $query;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
getData() will obtain the query and retrieve the records from the database. Now it might happen that we need to retrieve this list of data twice in one page load. It would be a waste to have to query the database twice. Therefore, we will have this method store the data in a protected property so that on subsequent requests it can simply return the data it has already retrieved. This property will be called _data. (&#039;&#039;&amp;lt;-- Naming convention conflict. Private or Protected data should be preceded with a &#039;_&#039; but as this reference is returned to the view where this data is directly accessed, this data can only be considered as public.&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
Here is the getData() method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source  lang=&amp;quot;php&amp;quot;&amp;gt;/**&lt;br /&gt;
 * Retrieves the hello data&lt;br /&gt;
 * @return array Array of objects containing the data from the database&lt;br /&gt;
 */&lt;br /&gt;
function getData()&lt;br /&gt;
{&lt;br /&gt;
    // Lets load the data if it doesn&#039;t already exist&lt;br /&gt;
    if (empty( $this-&amp;gt;_data ))&lt;br /&gt;
    {&lt;br /&gt;
        $query = $this-&amp;gt;_buildQuery();&lt;br /&gt;
        $this-&amp;gt;_data = $this-&amp;gt;_getList( $query );&lt;br /&gt;
    }&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 completed model looks like:&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;
 * Hellos Model for Hello World Component&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;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die();&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.application.component.model&#039; );&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Hello Model&lt;br /&gt;
 *&lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 */&lt;br /&gt;
class HellosModelHellos extends JModel&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * Hellos data array&lt;br /&gt;
     *&lt;br /&gt;
     * @var array&lt;br /&gt;
     */&lt;br /&gt;
    var $_data;&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the query&lt;br /&gt;
     * @return string The query to be used to retrieve the rows from the database&lt;br /&gt;
     */&lt;br /&gt;
    function _buildQuery()&lt;br /&gt;
    {&lt;br /&gt;
        $query = &#039; SELECT * &#039;&lt;br /&gt;
            . &#039; FROM #__hello &#039;&lt;br /&gt;
        ;&lt;br /&gt;
        return $query;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Retrieves the hello data&lt;br /&gt;
     * @return array Array of objects containing the data from the database&lt;br /&gt;
     */&lt;br /&gt;
    function getData()&lt;br /&gt;
    {&lt;br /&gt;
        // Lets load the data if it doesn&#039;t already exist&lt;br /&gt;
        if (empty( $this-&amp;gt;_data ))&lt;br /&gt;
        {&lt;br /&gt;
            $query = $this-&amp;gt;_buildQuery();&lt;br /&gt;
            $this-&amp;gt;_data = $this-&amp;gt;_getList( $query );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $this-&amp;gt;_data;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file is saved as models/hellos.php.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos View ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a model to retrieve our data, we need to display it. This view will be fairly similar to the view from the site section as well.&lt;br /&gt;
&lt;br /&gt;
Just as our model was automatically instantiated in the site, so it is in the administrator. Methods that start with &amp;quot;get&amp;quot; [e.g. getData()] in the model can be accessed using the get() method of the JView class. So our view has three lines: one to retrieve the data from the model, one to push the data into the template, and one to invoke the display method to display the output. Thus we have:&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;
 * Hellos View for Hello World Component&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;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die();&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.application.component.view&#039; );&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Hellos View&lt;br /&gt;
 *&lt;br /&gt;
 * @package    Joomla.Tutorials&lt;br /&gt;
 * @subpackage Components&lt;br /&gt;
 */&lt;br /&gt;
class HellosViewHellos extends JView&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * Hellos view display method&lt;br /&gt;
     * @return void&lt;br /&gt;
     **/&lt;br /&gt;
    function display($tpl = null)&lt;br /&gt;
    {&lt;br /&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();&lt;br /&gt;
&lt;br /&gt;
        // Get data from the model&lt;br /&gt;
        $items =&amp;amp; $this-&amp;gt;get( &#039;Data&#039;);&lt;br /&gt;
&lt;br /&gt;
        $this-&amp;gt;assignRef( &#039;items&#039;, $items );&lt;br /&gt;
&lt;br /&gt;
        parent::display($tpl);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file is saved as views/hellos/view.html.php.&lt;br /&gt;
&lt;br /&gt;
Look carefully at the almost hidden differences compared to &#039;&#039;site&#039;&#039; example. The data is stored in a variable that is encapsulated within the model. Because the data amount is huge due to using the very handy _getList(), the need for returning a reference instead of a value is obvious. This is handled in:&lt;br /&gt;
 $items =&amp;amp; $this-&amp;gt;get( &#039;Data&#039;);&lt;br /&gt;
Looking again at this line and you will notice another difference with respect to the &#039;&#039;site&#039;&#039; view.html.php. The calling of the model function is done implicitly. The actual model function name is getData(). In the &#039;&#039;site&#039;&#039; example you had to call following two lines:&lt;br /&gt;
 $model =&amp;amp; $this-&amp;gt;getModel();&lt;br /&gt;
 $greeting = $model-&amp;gt;getData();&lt;br /&gt;
Both lines are now taken care of by calling: &amp;lt;code&amp;gt;$this-&amp;gt;get( &#039;Data&#039;);&amp;lt;/code&amp;gt;. Under the surface of this &amp;lt;code&amp;gt;get()&amp;lt;/code&amp;gt; the &#039;Data&#039; is prefixed with &#039;get&#039; so when using this function make sure the model functions are preceded with &#039;get&#039;. This function can also be used in the &#039;&#039;site&#039;&#039; section. Keeping the data in the model and accessing it by reference, via &amp;lt;code&amp;gt;get()&amp;lt;/code&amp;gt; methods, is the preferred way of getting data from the model.&lt;br /&gt;
&lt;br /&gt;
==== The Hellos Template ====&lt;br /&gt;
&lt;br /&gt;
The template will take the data pushed into it from the view and produce the output. We will display our output in a simple table. While the frontend template was very simple, in the administrator we will need a minimal amount of extra logic to handle looping through the data.&lt;br /&gt;
&lt;br /&gt;
Here is our template:&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&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;
    foreach ($this-&amp;gt;items as &amp;amp;$row)&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 $row-&amp;gt;greeting; ?&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;
This template is saved as views/hellos/tmpl/default.php.&lt;br /&gt;
&lt;br /&gt;
You will notice that our output is enclosed in a form. Though this is not necessary now, it will be soon.&lt;br /&gt;
&lt;br /&gt;
We have now completed the basic part of the first view. We have added five files to the admin section of our component:&lt;br /&gt;
&lt;br /&gt;
* hello.php&lt;br /&gt;
* controller.php&lt;br /&gt;
* models/hellos.php&lt;br /&gt;
* views/hellos/view.html.php&lt;br /&gt;
* views/hellos/tmpl/default.php&lt;br /&gt;
&lt;br /&gt;
You can now add these files to the XML install file and give it a try!&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
We have now implemented a basic framework for the backend admin component. A list where all of the Hellos are displayed. The next chapter will extend this framework and add user interaction / database manipulation.&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 full admin 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>Upendotech</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=29719</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=29719"/>
		<updated>2010-08-08T16:28:54Z</updated>

		<summary type="html">&lt;p&gt;Upendotech: &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 Parts, 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 Parts 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 Part, [[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 will describe some basic details and in-depth explanation of the MVC pattern. This intermediate chapter is not required to complete the Hello model so if you think you understand the basics continue with [[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]].&lt;br /&gt;
&lt;br /&gt;
In the frontend solution (site section, parts 1,2 and 3) we developed the first part of our component. The frontend solution is based upon default Controllers, Views and Templates and you were &amp;quot;taken by the hand&amp;quot; and &amp;quot;left to trust&amp;quot; the default handling of the code. This is going to change in the Backend or Administration section of our Hello component ( parts 5 and 6) - we will have to develop all of the code that manages the application flow.&lt;br /&gt;
&lt;br /&gt;
== Site / Admin ==&lt;br /&gt;
Joomla! is a content management system. The &#039;&#039;&#039;frontend&#039;&#039;&#039; is used for presenting the users with content and allows certain logged in users to manipulate the content. The &#039;&#039;&#039;backend&#039;&#039;&#039; is responsible for administering the website framework (structuring / managing / controlling / maintaining). This division between (frontend) site-content and (backend) 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&#039; 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 Controllers, 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 Part it should be easy to follow the tutorial in the succeeding Parts.&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;See&#039;&#039;: [http://api.joomla.org/Joomla-Framework/User/JUser.html JUser object] for making user deviations in template module).&lt;br /&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 books with their corresponding due date. &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&lt;br /&gt;
                                                  // some complex views, multiple layouts might&lt;br /&gt;
                                                  // 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;
Another Way to do the same thing:&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
$pathToGeneralView = JPATH_COMPONENT_ADMINISTRATOR.DS. &amp;quot;views&amp;quot;.DS.&amp;quot;general&amp;quot;.DS;  &amp;lt;-- will return &#039;path/Joomla/administrator/components/com_example/views/general/&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. Also, having that many &#039;&#039;default&#039;&#039; forms can make it difficult to determine the context. On the other hand, the view.html.php cannot be renamed, and one is always forced to look at the directory name for the view.&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 models;&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 will 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/components/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/components/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 Joomla! 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, as 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 snippet of 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 the simple explanation is that post methods (i.e. 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;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Upendotech</name></author>
	</entry>
</feed>