Friday, May 27, 2011

Routing with Query Strings

The problem I'm having is that when I use the html helper to define a link
and add a query string it puts the action back into the url when I don't
want it there (second route).

I've got the following routes defined for the site I'm coding:

$consoles = 'ps3|360';
Router::connect('/:console/:arena/:controller/:slug/:action/*', array(),
array('console' => $consoles));
Router::connect('/:console/:arena/:controller/:slug/*',
array('action' => 'view', 'slug' => null),
array('console' => $consoles));
Router::connect('/:console/:arena/:controller/*',
array('action' => 'arena'),
array('console' => $consoles));
Router::connect('/:console/:arena/*',
array('controller' => 'arenas'),
array('console' => $consoles));

So an example of the more complex urls we'd have would be:

/ps3/blackops/ladders/doubles/join
/ps3/blackops/ladders/doubles - would use view action

I was defining the links manually but I'm making the switch to using the
html helper for links instead.

When the view action is being used I was looking to add some extra variables
to the end using the query string (as I don't really want view in the url -
plus I have a few variables). So I was hoping for something like this:
/ps3/blackops/ladders/clan?season=3&sort=wins&ord=asc (last couple would be
used for pagination)

but when I do this:

echo $html->link('Testing', array(
'console' => 'ps3',
'arena' => 'blackops',
'controller' => 'ladders',
'action' => 'view',
'slug' => 'clan',
'?' => array('season' => '3')
));

I'm getting: /ps3/blackops/ladders/clan/view?season=3

Is there a way of stopping the view from appearing automatically? If I don't
have the query string then it generates the urls how I expect.

Thanks in advance for any help provided.

--
View this message in context: http://cakephp.1045679.n5.nabble.com/Routing-with-Query-Strings-tp4433697p4433697.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: