Skip to content
Richard Louapre edited this page May 8, 2016 · 2 revisions

#Extensions

Other Extensions

###Model Extensions

###Controller Extensions

Controller Extensions support the ability to extend or override the actions defined in the base-controller. Once an extension is created, all of the dynamically managed controllers can support that method. This is useful, when implementing custom import/export or supporting new features in your base controller, without modifying the XQuerrail framework directly. There are 2 primary choices when extending the controller. Overriding the base controller globally or extending the base controller with new functions. The logic for the extensions are handled by the dispatcher in the following precedence:

  • Custom Controllers - If a controller is defined at the application level it supersedes everything
  • Extension Controller - Extensions override any base controller functions.
  • Base Controller - Base functions are called only if no custom or extension controller actions match the pattern given action defined by the base.

This is achievable by configuring the <controller-extension/> in /_config/config.xml. To define your custom extensions add the following entry:

<!--/_config/config.xml-->
<config>
...
<controller-extension  resource="/_extensions/controller.extension.xqy"/>
...    
</config>

When defining your custom extension you should place your extension in the /src/_extensions/ directory as noted by the @resource attribute.

The definition for your custom extension should follow the conventions noted below:

xquery version "1.0-ml";

(:The extension module namespace must be defined as follows:)
module namespace extension = "http://xquerrail.com/controller/extension";

(:Import the base controller to provide wrapping functions:)
import module namespace controller = "http://xquerrail.com/controller/base"
    at "/_framework/base/base-controller.xqy"; 
(:Import Request/Response:)
import module namespace request ="http://xquerrail.com/request"
    at "/_framework/request.xqy";
import module namespace response =  "http://xquerrail.com/response"
    at "/_framework/response.xqy";
    
(:Import the domain/base model to interact with model functions:)
import module namespace domain = "http://xquerrail.com/domain"
    at "/_framework/domain.xqy";    
import module namespace model = "http://xquerrail.com/model/base"
    at "/_framework/base/base-model.xqy";
(:~
 : Here is a sample method that creates an instance of the controller model
~:)    
declare function extension:instance() {
  model:create(controller:model(),request:params())
};

(:~
 : Implementation of a custom function
~:)
declare function extension:my-custom-function() {
  <todo>Implement your custom function {request:param("name")}</todo>
};

(:Add Custom Functions:)

(:Override an controller action or use :)

###Domain Extensions

###Engine Extensions

Clone this wiki locally