Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Generating Build Profiles with Zend_Dojo_BuildLayer

One of the chief benefits of a Dojo module layer is that it facilitates the creation of a custom build. Zend_Dojo_BuildLayer has functionality for generate build profiles.

The simplest use case is to utilize the generateBuildProfile() method and send the output to a file:

= new Zend_Dojo_BuildLayer(array(
'view'      => $view,
'layerName' => 'custom.main',

$profile   $build->generateBuildProfile();
$filename  APPLICATION_PATH '/../misc/scripts/custom.profile.js';

Just like generating layers, you may want to automate this via a dispatchLoopShutdown() plugin hook; you could even simply modify the one shown for generating layers to read as follows:

class App_Plugin_DojoLayer extends Zend_Controller_Plugin_Abstract

    public function 
        if (!
file_exists($this->layerScript)) {
        if (!
file_exists($this->buildProfile)) {

    public function 
generateDojoLayer() { /* ... */ }

    public function 
$profile $this->getBuild()->generateBuildProfile();


As noted, with module layers, you should only create the file once.

Build Profile options

The above functionality will suffice for most situations. The only way to customize build profile generation is to provide additional build profile options to utilize.

As an example, you may want to specify what type of optimizations should be performed, whether or not to optimize CSS files in the layer, whether or not to copy tests into the build, etc. For a listing of available options, you should read the Dojo Build documentation and accompanying documentation.

Setting these options is trivial: use the addProfileOption(), addProfileOptions(), or setProfileOptions() methods. The first method adds a single key and value option pair, the second will add several, and the third will overwrite any options with the list of key and value pairs provided.

By default, the following options are set:

    action:        "release",
    optimize:      "shrinksafe",
    layerOptimize: "shrinksafe",
    copyTests:     false,
    loader:        "default",
    cssOptimize:   "comments"

You can pass in whatever key and value pairs you want; the Dojo build script will ignore those it does not understand.

As an example of setting options:

// A single option:

// Several options:
'loader'   => 'xdomain',
'optimize' => 'packer',

// Or overwrite options:
'version'  => 'custom-1.3.1',
'loader'   => 'shrinksafe',
'optimize' => 'shrinksafe',

Zend Framework