how to get id from url in cake php

thecodedeveloper.com picture thecodedeveloper.com · Mar 9, 2012 · Viewed 10.7k times · Source

This is my action URL of which I'd like to get the 16.

http://localhost/carsdirectory/Galleries/add/16

Please help me.

Answer

Ben picture Ben · Mar 9, 2012
$this->params['pass']

Returns an array (numerically indexed) of URL parameters after the Action.

// URL: /posts/view/12/print/narrow      
Array
(
    [0] => 12
    [1] => print
    [2] => narrow
)

Another Method is - Just pass the parameter to the function itself like as follows:

function add($id=null)
{
   echo $id;
}

this will return your id