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 my-section-name
section.
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.
Url: www.example.com
Method used:FrontendController::homePage()
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.
Url: www.example.com/reservedWord
Method used:PagesController::reservedWord()
- if first url argument is a public method of your controller then it will be called
Url: www.example.com/myMethod
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.
Url: www.example.com/my-beautiful-nickname
Method used:PagesController::myBeautifulNickname()
- if first url argument is a valid unique name, it calls the corresponding FrontendController::section() or FrontendController::content() method. Here an example:
Url: www.example.com/my-section/my-content
Method used: section my-section will be loaded inFrontendController::section()
method, that will load my-content object throughFrontendController::content()
method - 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::homePage()
PagesController::homePageBeforeRender()
(if it exists)