To fit variegated needs that you can encounter developing a frontend application, BEdita comes with a series of callback methods that allows to find and handle data. Before having a look at this callbacks let's go to see what happens in a standard frontend flow.
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-one, in browser address bar we'll write
http://www.example.com/section-one
Everything 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
http://www.example.com/myCustomMethod
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.
If none reserved word or controller public method 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 $section
.
Finally the view is rendered.
Note: for the complete list of route rules followed in frontend apps it's raccomended to read Routing rules in frontend applications article.
Callback Methods
There are four main callbacks always called that can be used to insert logic before or after controller actions:
- beforeCheckLogin 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 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. If exists a callback [methodToCallBeforeFilter is called before the main method (for example sectionBeforeFilter is called before section method) and another callback [methodToCall]BeforeRender is called soon after the main method.
Similar callbacks are handled in section and contents methods using the section/content unique name as defined in bedita-app/lib/BeLib::variableFromNickname()
, i.e. [sectionNickname]BeforeFilter and [contentNickname]BeforeFilter and [sectionNickname]BeforeRender and [contentNickname]BeforeRender. In our example the callbacks will be sectionOneBeforeFilter() and sectionOneBeforeRender().
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 [sectionNickname]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 paginate sections' contents, group BEdita objects for type, etc... .
Instead the [sectionNickname]BeforeRender callback usually can be used to manipulate the $section
array that is set in section method (you can find it in $this->viewVars["section"]
).
Recap
The frontend flow of a section/content request can be summarized in this way:
- browser request
- call beforeCheckLogin method
- call beditaBeforeFilter method
- if exists call sectionBeforeFilter or contentBeforeFilter through route method
- routing section/content method through route method
- if exists call [sectionNickname]BeforeFilter method
- if exists and content is requested call [contentNickname]BeforeFilter method
- recover section and content data by nickname
- if exists call [sectionNickname]BeforeRender method
- if exists and content is requested call [contentNickname]BeforeRender method
- if exists call sectionBeforeRender or contentBeforeRender through route method
- call beditaBeforeRender method
- render view
- call beditaAfterFilter method