Saturday 16 June 2012

CAKEPHP Route Concept.

Rotes in CAKEPHP is used to map for exact Controller and Action. It is not redirecting.

Default Routes:

Some default routes come with CAKEPHP inside the file routes.php (app/config/routes.php).
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
The first parameter '/' is the root of the domain. The second parameter sets PagesController::display() action with first parameter as home.

Wildcard in Routes:

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
In above route setting maps with controller pages and action display. All things after /pages/ will be passed as parameter to action display.

Routes with named elements:

Router::connect('/namedelement/:action/*', array('controller' => 'pages'));
Here named element called 'action' in this route. Named elements are prefixed with ':'. These named elements are automatically passed to controller with Controller::$params and in same way to the view class.

No comments:

Post a Comment