Archived

Difference between revisions of "Developing a MVC Component/Adding a view to the site part"

From Joomla! Documentation

< Archived:Developing a MVC Component
(New page: {{underconstruction}} == Indroduction == This tutorial is part of the Developing a Model-View-Controller (MVC) Component for Joomla!1.6 tutorial. You are encouraged to read the precede...)
 
Line 12: Line 12:
  
 
<source lang="php">
 
<source lang="php">
<?php defined(_JEXEC) or die('Restricted access');
+
<?php
 
+
// No direct access to this file
 +
defined(_JEXEC) or die('Restricted access');
 +
// import joomla controller library
 +
jimport('joomla.application.component.controller');
 +
// Get an instance of the controller prefixed by HelloWorld
 +
$controller = JController::getInstance('HelloWorld');
 +
// Perform the Request task
 +
$controller->execute(JRequest::getCmd('task'));
 +
// Redirect if set by the controller
 +
$controller->redirect();
 
</source>
 
</source>
 
You can test this basic component by putting ''index.php?option=com_helloworld'' in your browser address (don't forget to prefix this address by your Joomla!1.6 installation path).
 
You can test this basic component by putting ''index.php?option=com_helloworld'' in your browser address (don't forget to prefix this address by your Joomla!1.6 installation path).
  
 +
== Packaging the component ==
 
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11373/45535/com_helloworld-1.6-part1.zip archive] and install it using the extension manager of Joomla!1.6. You can test this basic component by putting ''index.php?option=com_helloworld'' or ''administrator/index.php?option=com_helloworld'' in your browser address. You can also noticed that the ''Hello World!'' component is visible in the administrator site of your Joomla!1.6 installation under the ''Components'' menu.
 
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11373/45535/com_helloworld-1.6-part1.zip archive] and install it using the extension manager of Joomla!1.6. You can test this basic component by putting ''index.php?option=com_helloworld'' or ''administrator/index.php?option=com_helloworld'' in your browser address. You can also noticed that the ''Hello World!'' component is visible in the administrator site of your Joomla!1.6 installation under the ''Components'' menu.
  

Revision as of 02:51, 3 November 2009

This page has been archived. This page contains information for an unsupported Joomla! version or is no longer relevant. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Cdemko (talk| contribs) 14 years ago. (Purge)

Indroduction[edit]

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

In the Joomla!1.6 framework, third party components authors divide their code in three main parts:

  • models They are responsible for managing the data
  • controllers They perform tasks, set and get states of the models and ask the views to display
  • views They display the content according to the type (html, raw, pdf, ...) and the layout chosen by the controllers

Setting the controller[edit]

In the core code of Joomla, there is a class able to manage controllers: JController. This class has to be extended to be used it in our component. In the file site/helloworld.php (entry point of our Hello World component), put these lines

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

You can test this basic component by putting index.php?option=com_helloworld in your browser address (don't forget to prefix this address by your Joomla!1.6 installation path).

Packaging the component[edit]

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla!1.6. You can test this basic component by putting index.php?option=com_helloworld or administrator/index.php?option=com_helloworld in your browser address. You can also noticed that the Hello World! component is visible in the administrator site of your Joomla!1.6 installation under the Components menu.

Contributors[edit]