In frontend applications you will normally have just this rule in your
config/routes.php file [standard CakePHP file for routing rules]:
Router::connect( '/*', array( 'controller' => 'pages', 'action' => 'route' ) );
That means: every URL (/*) should be passed to
PagesController::route() (inherited from
FrontendController class) . This
route() method will decide which actions to take.
Most of the URLs handled will be in the form
/my-section-name/my-content-name - that will cause loading of section with unique name
my-section-name and content with unique name
my-content-name located in
But the general routing rules, in
route() method, are as follows:
- if there aren't url arguments (i.e. "/") then will be used the reserved word "homePage" for calling the method with the same name.
Action performed: load first Section of the relative Publication or the Publication if no section is found (see Publication module on BEdita backend).
You can ovverride this method in your controller to fit your home page at your needs;
- if first url argument is a reserved word (defined in configuration variables "defaultReservedWords" and "cfgReservedWords") it means that no object will have this unique name. So it will try to call a method with this same reserved name. Some reserved words have an own method in FrontendController that you may override in your controller.
- if first url argument is a public method of your controller then it will be called
Method used: PagesController::myMethod()
- if first url argument is a valid unique name and there is a public method of your controller with a corresponding name (as defined in
bedita-app/lib/BeLib::variableFromNickname()), it will be called.
- if first url argument is a valid unique name, it calls the corresponding FrontendController::section() or FrontendController::content() method. Here an example:
Method used: section my-section will be loaded in
FrontendController::section()method, that will load my-content object through
- if none of the above points are matched then an exception is thrown causing a 404 http error
Before and after every method called from FrontendController::route() (except), two callbacks methods are triggered if they exist: methods with same name and suffix -BeforeFilter / -BeforeRender . For example when the homePage() method is used, the flow will be:
PagesController::homePageBeforeFilter()(if it exists)
PagesController::homePageBeforeRender()(if it exists)