MVC in Joomla
Components
A component is in fact a seperate application. It contains it’s core, Model, View, Controller.
Module
Modules are extensions which present certain pieces of information on site.
Plugin
A plugin is a function which is performed on a part of Joomla before this part is shown.
Active Record
The Active Record is implemented using JTable. It is used for creating, reading, updating, and deleting records in database table. The Active Record file for component is at:
administrator/components/com_xxx/tables/yyy.php
Using Active Record save data:
$row =& JTable::getInstance('xxx', 'Table');
$post = JRequest::get( 'post' );
if (!$row->bind( $post )) {
JError::raiseError(500, $row->getError() );
}
$isNew = ($row->id == 0);
if (!$row->check()) {
JError::raiseError(500, $row->getError() );
}
if (!$row->store()) {
JError::raiseError(500, $row->getError() );
}
$row->checkin();
Model
The Model is implemented using JModel, the Model file for component is at:
components/com_xxx/models/yyy.php
View
The View is implemented using JView, the view file for component is at:
components/com_xxx/views/yyy/view.html.php
Controller
The Controller is implemented using JController, the controller file for component is at:
components/com_xxx/controller.php
Using Controller object from Component core file:
require_once(JPATH_COMPONENT.DS.'controller.php');
// Create the controller
$controller = new XxxController();
// Register Extra tasks
$controller->registerTask( 'new' , 'edit' );
$controller->registerTask( 'apply', 'save' );
// Perform the Request task
$controller->execute(JRequest::getVar('task', null, 'default', 'cmd'));
$controller->redirect();