Developing a MVC Component/Basic backend: Difference between revisions
From Joomla! Documentation
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
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
- Developing a Basic Component
- Adding a view to the site part
- Adding a menu type to the backend part
- Adding a model to the site part
- Adding a variable request in the menu type
- Using the database
- Basic backend
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
- helloworld.xml
- site/index.html
- site/helloworld.php
- site/views/index.html
- site/views/helloworld/index.html
- site/views/helloworld/view.html.php
- site/views/helloworld/tmpl/index.html
- site/views/helloworld/tmpl/default.xml
- site/models/index.html
- site/models/helloworld.php
- site/views/helloworld/tmpl/default.php
- admin/index.html
- admin/helloworld.php
- admin/sql/index.html
- admin/sql/install.mysql.utf8.sql
- admin/sql/uninstall.mysql.utf8.sql
- admin/sql/update.mysql.utf8.sql
- admin/models/index.html
- admin/models/fields/index.html
- admin/models/fields/helloworld.php
- admin/tables/index.html
- admin/tables/helloworld.php
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.