Archived

Developing a MVC Component/Basic backend: Difference between revisions

From Joomla! Documentation

Cdemko (talk | contribs)
Cdemko (talk | contribs)
No edit summary
Line 13: Line 13:


== Basic backend ==
== Basic backend ==
Designing the backend interface leads us to create at least a Model-View-Controller triptych. We have to modified the administrator entry point of our component, the ''admin/helloworld.php'' file
<span id="admin/helloworld.php">
''admin/helloworld.php''
<source lang="php">
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
// Redirect if set by the controller
$controller->redirect();
</source>
</span>
== Create the general controller ==
The entry point now get an instance of a ''HelloWorld'' prefixed controller. Let create a basic controller for the administrator part:
<span id="admin/helloworld.php">
''admin/helloworld.php''
<source lang="php">
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of HelloWorld component
*/
class HelloWorldController extends JController
{
/**
* display task
*
* @return void
*/
function display($cachable = false)
{
// set default view if not set
JRequest::setVar('view', JRequest::getCmd('view', 'HelloWorldList'));
// call parent behavior
parent::display($cachable);
}
}
</source>
</span>
This controller will display the 'HelloWorldList'' view by default.
== Create the ''HelloWorldList'' view ==





Revision as of 11:08, 11 November 2009

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) 16 years ago. (Purge)

Articles in this series

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 previous parts of the tutorial before reading this.

Basic backend

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

admin/helloworld.php

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

Create the general controller

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

admin/helloworld.php

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

This controller will display the 'HelloWorldList view by default.

Create the HelloWorldList view

Packaging the component

Content of your code directory

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

Contributors