Actions

Difference between revisions of "How to override the component mvc from the Joomla! core"

From Joomla! Documentation

Line 1: Line 1:
 
There may be occasions where you would like to override the way a Joomla! Components MVC to add a little new functionality or complete customize a component. Component MVC can be overridden by using a class with same name as we have on a component and we need to loading by using a system plugin before component are dispatched by application.
 
There may be occasions where you would like to override the way a Joomla! Components MVC to add a little new functionality or complete customize a component. Component MVC can be overridden by using a class with same name as we have on a component and we need to loading by using a system plugin before component are dispatched by application.
  
What you can override on MVC component?
+
You can create your own plugin to do this.
- View classes: [Component]View[Name]
+
- Model classes: [Component]Model[Name]
+
- Controller classes: [Component]Controller[Name]
+
  
Need to override layout?
+
<code>
[[http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core]]
+
class plgSystemComContentOverride extends JPlugin {
 +
 +
      public function __construct(&$subject, $config = array()) {
 +
          parent::__construct($subject, $config);
 +
      }
 +
 +
      public function onAfterRoute() {
 +
          $app = JFactory::getApplication();
 +
          if('com_content' == JRequest::getCMD('option') && !$app->isAdmin()) {
 +
              require_once(dirname(__FILE__) . DS . 'comcontentoverride' . DS . 'my_content_controller.php');
 +
          }
 +
      }
 +
}
 +
</code>
  
Getting a head-start with overrides
+
On examples bellow we are using a [http://www.example.com Override MVC plugin]
  
 +
== Getting a head-start with overrides ==
 +
 +
You can override by templating or by application scope(frontned/backend).
 +
 +
== Using a templating method ==
  
 
Override Base Component Controller
 
Override Base Component Controller
TEMPLATE_NAME/code/EXTENSION_NAME/CONTROLLER.php
+
<source lang="xml">TEMPLATE_NAME/code/COMPONENT_NAME/CONTROLLER.php</source>
 
Override Another Component Controller
 
Override Another Component Controller
TEMPLATE_NAME/code/EXTENSION_NAME/controllers/CONTROLLER_NAME.php
+
<source lang="xml">TEMPLATE_NAME/code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php</source>
 +
Override Models
 +
<source lang="xml">TEMPLATE_NAME/code/COMPONENT_NAME/models/MODEL_NAME.php</source>
 +
Override Views
 +
<source lang="xml">TEMPLATE_NAME/code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php</source>
  
 +
== Using application scope method ==
 +
 +
You can override by create a <code>code</code> folder on base path from application.
 +
 +
'''Site General Override'''
 +
 +
<source lang="xml">code/COMPONENT_NAME/CONTROLLER.php</source>
 +
Override Another Component Controller
 +
<source lang="xml">code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php</source>
 
Override Models
 
Override Models
TEMPLATE_NAME/code/EXTENSION_NAME/models/CONTROLLER_NAME.php
+
<source lang="xml">code/COMPONENT_NAME/models/MODEL_NAME.php</source>
 +
Override Views
 +
<source lang="xml">code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php</source>
  
If you use multiple templating on your site you can override by create a "local" folder on root folder and on administrator folder.
+
'''Administrator General Override'''
 +
 
 +
<source lang="xml">administrator/code/COMPONENT_NAME/CONTROLLER.php</source>
 +
Override Another Component Controller
 +
<source lang="xml">administrator/code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php</source>
 +
Override Models
 +
<source lang="xml">administrator/code/COMPONENT_NAME/models/MODEL_NAME.php</source>
 +
Override Views
 +
<source lang="xml">administrator/code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php</source>

Revision as of 07:38, 22 March 2012

There may be occasions where you would like to override the way a Joomla! Components MVC to add a little new functionality or complete customize a component. Component MVC can be overridden by using a class with same name as we have on a component and we need to loading by using a system plugin before component are dispatched by application.

You can create your own plugin to do this.

class plgSystemComContentOverride extends JPlugin {

      public function __construct(&$subject, $config = array()) {
         parent::__construct($subject, $config);
     }

     public function onAfterRoute() {
         $app = JFactory::getApplication();
         if('com_content' == JRequest::getCMD('option') && !$app->isAdmin()) {
             require_once(dirname(__FILE__) . DS . 'comcontentoverride' . DS . 'my_content_controller.php');
         }
     } 
}

On examples bellow we are using a Override MVC plugin

Getting a head-start with overrides

You can override by templating or by application scope(frontned/backend).

Using a templating method

Override Base Component Controller

TEMPLATE_NAME/code/COMPONENT_NAME/CONTROLLER.php

Override Another Component Controller

TEMPLATE_NAME/code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php

Override Models

TEMPLATE_NAME/code/COMPONENT_NAME/models/MODEL_NAME.php

Override Views

TEMPLATE_NAME/code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php

Using application scope method

You can override by create a code folder on base path from application.

Site General Override

code/COMPONENT_NAME/CONTROLLER.php

Override Another Component Controller

code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php

Override Models

code/COMPONENT_NAME/models/MODEL_NAME.php

Override Views

code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php

Administrator General Override

administrator/code/COMPONENT_NAME/CONTROLLER.php

Override Another Component Controller

administrator/code/COMPONENT_NAME/controllers/CONTROLLER_NAME.php

Override Models

administrator/code/COMPONENT_NAME/models/MODEL_NAME.php

Override Views

administrator/code/COMPONENT_NAME/views/VIEW_NAME/VIEW_NAME(.FORMAT).php