To fit variegated needs that you can encounter developing a frontend application, BEdita comes with a series of callback methods that allow to find and handle data. Before having a look at this callbacks let's go to see what happens in a standard frontend flow.
note: the italic grey text parts referred to BEdita 3.1 version. In BEdita 3.0.x series is missing.
Frontend Application Flow
Supposing we have a BEdita publication reachable from
http://www.example.com and we want to see the contents of a section with nickname section-1, in browser address bar we'll write
Everything that doesn't start with pages is handled by route method that decide what to do. So if you have a custom method in Pages Controller you can call it in standard CakePHP mode
route method gets first parameters passed by URL (in our case section-1), check if it's a reserved word as defined in configuration files and eventually try to call method with that name. So you could put in your bedita-app/config/bedita.cfg.php the reserved word myCustomMethod
$config["cfgReservedWords"] = array("myCustomMethod");
and call directly
If none reserved word is found then BEdita consider the parameter a nickname, check if it corresponds to a section object or not and call respectively section method or content method. These two methods will load all section and contents data and set to view the array
Finally the view is rendered.
There are two (four in 3.1 release) main callbacks always called that can be used to insert logic before or after controller actions:
- beforeCheckLogin (present from 3.1 release) called by FrontendController::initAttributes method is executed before check login operation is performed. It's useful if you want to skip the user check login operation for specific items setting to true the AppController::$skipCheck attribute. Note that the checkLogin method is called before beditaBeforeFilter.
- beditaBeforeFilter called by AppController::beforeFilter method is executed before every action in the controller;
- beditaBeforeRender called by AppController::beforeRender method is executed after controller action but before view is rendered.
- beditaAfterFilter (present from 3.1 release) called by AppController::afterFilter method is executed after the render is done. It's the last thing made by controller.
In addition some specific callbacks are called if respective method exists. When a reserved word is found a callback [reservedWord]BeforeFilter (my_custom_methodBeforeFilter) is called before reservedWord method and another callback [reservedWord]BeforeRender (my_custom_methodBeforeRender) is called soon after reservedWord method.
Similar callbacks are handled in section method using the section (and content from 3.1 release) nickname replacing "-" with "_" in method name, i.e. [section-nickname]BeforeFilter (and [content-nickname]BeforeFilter from 3.1 release) and [section-nickname]BeforeRender (and [content-nickname]BeforeRender from 3.1 release). In our example the callbacks will be section_1BeforeFilter() and section_1BeforeRender().
So you can define these callback methods in Pages Controller to customize punctually the way to find results and manipulate the
$section array before render view.
In particular the [section-nickname]BeforeFilter callback can be used to set parameters and class attributes to put the section method in the condition to find the expected result. For example changing the
FrontendController::$sectionOptions attribute like you can see in the blog posts "Customizing Frontend Applications" part 1, 2 and 3 you can page sections' contents, group BEdita objects for type, etc... .
Instead the [section-nickname]BeforeRender callback usually can be used to manipulate the $section array that is setted in section method (you can find it in $this->viewVars["section"]).
The frontend flow of a section/content request can be summarized in this way:
- browser request
- call beforeCheckLogin method (from 3.1 BEdita version)
- call beditaBeforeFilter method
- routing section/content method through route method
- if exists call [section-nickname]BeforeFilter method
- if exists and content is requested call [content-nickname]BeforeFilter method (from 3.1 BEdita version)
- recover section and content data by nickname
- if exists call [section-nickname]BeforeRender method
- if exists and content is requested call [content-nickname]BeforeRender method (from 3.1 BEdita version)
- call beditaBeforeRender method
- render view
- call beditaAfterFilter method (from 3.1 BEdita version)