In APP/routes.php :
// www.example/com/Controllername Router::connect('/Controllername', array('controller'=>'Controllername', 'action'=>'index')); // www.example.com/Controllername/param1/param2 Router::connect('/Controllername/:param1/:param2', array('controller'=>'Controllername', 'action'=>'index'), array('pass' => array('param1', 'param2')));
and your controller:
// set to null/a value to prevent missing parameter errors public function index($param1=null, $param2=null) { //echo $param1 . ' and ' . $param2; }
When creating links:
array('controller'=>'Controllername', 'action'=>'index', 'param1'=>'foo', 'param2'=>'bar');
The order of questions. Change paramX to whatever you want, i.e. country and town
Note that this does not apply: controllername/param1 - both must be present in this example.
There are other ways to achieve this.
source share