0

On my site I need to have URLs of pages in this manner: /category/page4, so parameter passed into a controller is a number after the word "page". I managed to get URLs in the following manner: /category/page/4 (with an extra slash) using this code:

$router->addRoute('categoryPages', new Zend_Controller_Router_Route( '/category/page/:page', array( 'controller' => 'caegory', 'action' => 'index' ), array( 'page' => '\d+' ) )); 

I would expect to have URLs like /category/page4 with the following modification of this code:

// Simply removed one slash '/category/page:page' 

However, this code doesn't create routing I need. What is my mistake?

1 Answer 1

1

You can't do this with Zend_Controller_Router_Route, named variables must sit on their own adjacent to either the url delimiter (slash), or the start/end of the route.

Instead you could do this as a regular expression route:

$router->addRoute('categoryPages', new Zend_Controller_Router_Route_Regex( 'category/page(\d+)', array( 'controller' => 'caegory', 'action' => 'index' ), array( 1 => 'page' ), 'category/page%s' )); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.