Skip the query string for cake style url in cakephp and provide ext from HTML

What I'm trying to achieve:

When the user passes this:

/results?val=real&x=1&y=0 

he must show:

 /results/real.html?x=1&y=0 

and from Action I should still have access to $this->request->query['val'] , which should be equal to real

What have i done so far?

I am using CakePHP 2.4

 Router::parseExtensions('html'); Router::connect('/results/:val', array('controller'=>'Post','action'=>'results', '?' => array('val'=>'[A-Za-z0-9]-_ +','x'=>'[0-9]+','y'=>'[0-9]+'))); 
+8
php cakephp cakephp-routing
source share
1 answer

Just define the route as shown below in the routes.php file.

 Router::connect( '/results/:val', array( 'controller' => 'Post', 'action' => 'results', ), array( 'pass' => array('val') ) ); 

You can set the parameters as shown below to create the link the way you want.

 echo Router::url(array( 'controller' => 'Post', 'action' => 'results', 'val' => 'real', 'ext' => 'html', '?' => array('x' => '1', 'y' => '0') )); 

What is displayed: results/real.html?x=1&y=0

+10
source share

All Articles