Bancha

v1.2.2 - Official User Guide



Dispatchers

Dispatchers are classes that performs many operation before the rendering process. They are tipically fired by the controllers. As example, the Website controller fires many of the dispatchers described below.

The Bancha core dispatcher are located inside the core/dispatchers directory.

Instead, the folder for the dispatchers of your application (if you need to create a new one), is application/dispatchers. To add a new dispatcher, create a new file in that directory using dispatcher_name.php as filename and Dispatcher_name as class name.

You can find a sample dispatcher here: application/dispathcers/dispatcher_example.php

You can load a dispatcher using the following function:

$this->load->dispatcher('foo');

//Then, use it as an object of the super-object
$this->dispatcher->method_name();

//You can specify the name as second optional parameter
$this->load->dispatcher('name', 'foo');
$this->foo->method_name();

Default dispatcher

This is the default dispatcher of the website: is responsable of allocating the current page, the optional record/records and loading the rendering process. Called from the router action of the Website controller:

$this->load->dispatcher('default');
$this->dispatcher->start();

Image dispatcher

This dispatcher handles the Image presets. When a preset cached file does not exists, an action on the website controller will be called and that action then fires the image dispatcher. This, will performs all the graphical preset operations and after saving the file on the disk (to cache the next request) will output the content to the client. Called from the image_router action of the Website controller:

$this->load->dispatcher('images');

$data = array(
    'type'      => 'Products',
    'field'     => 'first_image',
    'id'        => 123,
    'preset'    => 'little-square',
    'filename'  => 'path/to/original.jpg',
    'ext'       => 'jpg'
);

$this->dispatcher->retrieve($data);

Read more about the Image presets.

Resources dispatcher

This dispatcher can minify css and javascript resources. It will be automatically used when using the minify function of the Frontend helper. That function generates a URL that will be routed to the resources dispatcher and the requested resources will be compressed, merged, cached and then sent to the client. Called from the minify action of the Website controller:

$resources = array('path/js/jquery.js', 'path/js/application.js');

$this->load->dispatcher('resources');
$this->dispatcher->minify('themename', $resources, 1);

Bancha - Copyright 2011-2012(C) Squallstar Studio - www.squallstar.it