Friday 13 February 2009
Facebook StumbleUpon Twitter Google+ Pin It

CakePHP Routing With Parameters

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'];
    
    //
}

Parthiv Patel
Bhaishri Info Solution
Sr. PHP Developer
Limdi Chowk, AT PO. Nar, Di. Anand
Nar, Gujarat
388150
India
pparthiv2412@gmail.com
7383343029
DOB: 12/24/1986

No comments: