© 2015 X2Engine Inc.

Customization Framework

From X2Engine
Revision as of 18:15, 19 October 2012 by Drsimonz (talk | contribs) (Overriding Files)
Jump to: navigation, search


Introduction

X2EngineCRM provides the means to manually customize classes and templates without modifying the source files. This can be performed by creating new files in custom. The need for this arises because the source files may be overwritten (and their customizations destroyed) during each software update, whereas if customizations are stored in other files, they remain in effect, and barring any incompatibilities between new versions and customizations in those files, they will still work as intended.

Overview

(in progress)


Overriding Files

Practically any php file used in X2Engine can be overridden. X2Engine's customization framework resides in the /custom directory, which mirrors the structure of the source code. For example, /custom/protected/components corresponds to /protected/components. Any php file placed in /custom will be used instead of the original.

Extending Controllers

X2Engine is built on Yii, which uses MVC (model-view-controller) architecture. Overriding an entire file is practical when dealing with views or smaller classes (such as models), but controllers can present a greater challenge. It's only a matter of time before we update one of the 1500+ lines of code in a controller. This means you have to manually find and transfer your changes from the old version, which is time-consuming. To remedy this, we allow substitution of any controller in X2Engine with an extended class.

Whenever a controller is loaded, X2Engine checks for the same filename with "My" at the beginning. For example, if you want to override a single action to ContactsController, you can create a file called MyContactsController in /custom/protected/modules/contacts/controllers containing the following:

<?php
class MyContactsController extends ContactsController {
    function actionIndex() {
        echo 'Hello World!';
    }
}
?>

This file will automatically be used instead of ContactsController and should still work if ContactsController is changed in an update. You may still need to manually merge changes if an update alters the same part of the controller that you changed, but it will be much easier to find.

Known Issues

Currently, only php files can be substituted. To change a CSS or Javascript file you would have to edit the original file.