Showing posts with label routes. Show all posts
Showing posts with label routes. Show all posts

Saturday, February 14, 2009

CakePHP Routing With Parameters

Anything you need to know with cakePHP routing can be found here.

Here is an example to illustrate routing with parameters.

/config/routes.php

Router::connect(
'/:controller/:year/:month/:day',
array('action' => 'index', 'day' => null),
array(
'year' => '[12][0-9]{3}',
'month' => '(0[1-9]|1[012])',
'day' => '(0[1-9]|[12][0-9]|3[01])'
)
);


Parameters can be access like this:

/controllers/controller.php

function index(){
// params is stored in $this->params
$year = $this->params['year'];
$month = $this->params['month'];
$day = $this->params['day'];

//
}

Friday, February 13, 2009

How to Route Admin Actions in CakePHP 1.2

This is how to setup the routing:

Router::connect('/admin/:controller/:action/*', array('admin'=>'true','prefix'=>'admin', 'controller'=>'controller', 'action'=>'action'));