Re: Need help with reverse routing

2012-08-10 Thread lowpass
Here's a generic element I use for pagination:

http://pastebin.com/JvKbyWUi

Perhaps you can modify that to your own needs. With Cake 2.x I've had
to make some changes to what I had been using. I suppose that I must
be doing something wrong that it requires the AppController snippet.

I think your route could be improved a bit:

Router::connect(
'/:state/:city/:page/:slug',
array(
'controller' = 'pages',
'action' = 'display',
'level' = 'town'
),
array(
'state' = '[a-z]{2}',
'city' = '[-a-z]+',
'page' = '[0-9]+',
'slug' = '[-a-z]+',
'pass' = array('page', 'slug')
)
);


I've added the slug to the URL, which allows you to pass it as an
action param. Otherwise, I'm not sure what good it would do you.

I've also made a better regex for state, and sluggified city -- a
name with a space or apostrophe would not match your regex. Because
you want the city name to appear in URLs, you'll need to store both
the display text and slug for each city.

As for what's being passing as params, personally, I would pass state,
city, and slug. I also think it's a bit odd that this is pointing to
PagesController. But then, I don't know the details so ...

On Fri, Aug 10, 2012 at 2:33 PM, Mark Wratten m...@trimar.com wrote:
 I'm looking for some help with reverse routing as the documentation is a bit
 thin. Particularly for use with rendering objects such as PaginatorHelper.

 I have a URL in the format - /state/city/page/slug which I route with -
 Router::connect('/:state/:city/:page/*', array(
 'controller' = 'pages', 'action' = 'display', 'level' = 'town'), array(
 'state' = '[a-z][a-z]', 'city' = '[a-z]+', 'page' = '[^/]*', 'pass' =
 array('page')));

 That works fine in the forward direction, but how do I get the
 PaginatorHelper to assemble the URL with the state and city pieces?

 If I add another route for ajax requests, such as -
 Router::connect('/ajax/:controller/:action/*');

 That also works in the forward direction, but the URL generated by
 PaginatorHelper in the previous case now generates the URL in the form -
 /ajax/pages/display/...
 So How do you tell the reverse routing which rule to use?

 If I need to resort to a custom router, how do you tell the the Cake
 rendering functions to use the custom router?

 Thanks in advance

 Mark

 --
 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com.
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php?hl=en-US.



-- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Need help with reverse routing

2012-08-10 Thread Mark Wratten
cricket - thanks for the reply, I will try it and see if it works.

Thanks

Mark

On Friday, August 10, 2012 4:18:32 PM UTC-4, cricket wrote:

 Here's a generic element I use for pagination: 

 http://pastebin.com/JvKbyWUi 

 Perhaps you can modify that to your own needs. With Cake 2.x I've had 
 to make some changes to what I had been using. I suppose that I must 
 be doing something wrong that it requires the AppController snippet. 

 I think your route could be improved a bit: 

 Router::connect( 
 '/:state/:city/:page/:slug', 
 array( 
 'controller' = 'pages', 
 'action' = 'display', 
 'level' = 'town' 
 ), 
 array( 
 'state' = '[a-z]{2}', 
 'city' = '[-a-z]+', 
 'page' = '[0-9]+', 
 'slug' = '[-a-z]+', 
 'pass' = array('page', 'slug') 
 ) 
 ); 


 I've added the slug to the URL, which allows you to pass it as an 
 action param. Otherwise, I'm not sure what good it would do you. 

 I've also made a better regex for state, and sluggified city -- a 
 name with a space or apostrophe would not match your regex. Because 
 you want the city name to appear in URLs, you'll need to store both 
 the display text and slug for each city. 

 As for what's being passing as params, personally, I would pass state, 
 city, and slug. I also think it's a bit odd that this is pointing to 
 PagesController. But then, I don't know the details so ... 

 On Fri, Aug 10, 2012 at 2:33 PM, Mark Wratten ma...@trimar.comjavascript: 
 wrote: 
  I'm looking for some help with reverse routing as the documentation is a 
 bit 
  thin. Particularly for use with rendering objects such as 
 PaginatorHelper. 
  
  I have a URL in the format - /state/city/page/slug which I route with - 
  Router::connect('/:state/:city/:page/*', array( 
  'controller' = 'pages', 'action' = 'display', 'level' = 'town'), 
 array( 
  'state' = '[a-z][a-z]', 'city' = '[a-z]+', 'page' = '[^/]*', 'pass' 
 = 
  array('page'))); 
  
  That works fine in the forward direction, but how do I get the 
  PaginatorHelper to assemble the URL with the state and city pieces? 
  
  If I add another route for ajax requests, such as - 
  Router::connect('/ajax/:controller/:action/*'); 
  
  That also works in the forward direction, but the URL generated by 
  PaginatorHelper in the previous case now generates the URL in the form - 
  /ajax/pages/display/... 
  So How do you tell the reverse routing which rule to use? 
  
  If I need to resort to a custom router, how do you tell the the Cake 
  rendering functions to use the custom router? 
  
  Thanks in advance 
  
  Mark 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups 
  CakePHP group. 
  To post to this group, send email to cake...@googlegroups.comjavascript:. 

  To unsubscribe from this group, send email to 
  cake-php+u...@googlegroups.com javascript:. 
  Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
  
  


-- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.