Try this:

     $route = new Zend_Controller_Router_Route_Regex(
      'foo/(\d+)(?:/(\w+))?',
       array(
         'module' => 'MyModule',
         'controller' => 'Foo',
         'action' => 'index'
       ),
       array(
         1 => 'id',
         2 => 'action'
       ),
       'foo/%d/%s'
     ); 

"?:" at the begin of the second match will tell PHP to ignore it.
I didn't try it but should work.

Giuliano


Colin Guthrie-6 wrote:
> 
> Hi,
> 
> I've just run into a problem when trying to assemble a route into a link.
> 
> Allow me to demonstrate:
> 
>      $route = new Zend_Controller_Router_Route_Regex(
>       'foo/(\d+)(/(\w+))?',
>        array(
>          'module' => 'MyModule',
>          'controller' => 'Foo',
>          'action' => 'index'
>        ),
>        array(
>          1 => 'id',
>          3 => 'action'
>        ),
>        'foo/%d/%s'
>      );
> 
>      $router = Zend_Controller_Front::getInstance()->getRouter();
>      $router->addRoute('MyRoute', $route);
> 
> 
> This route should match urls:
>   * /foo/123 (action = index)
>   * /foo/123/ (action = index) (this works due to the matcher striping 
> off leading/trailing slashes)
>   * /foo/123/bar (action = bar)
> 
> If I were to put the / as a required part of the regexp like this:
>       'foo/(\d+)/(\w+)?'
> then this will never match the index case without specifying it 
> explicitly (i.e. the first two example URLs above will not match).
> [...]
> 

-- 
View this message in context: 
http://www.nabble.com/Ignoring-matches-in-Zend_Controller_Router_Route_Regex-%28possible-assemble%28%29-bug%29-tp19747692p19756128.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to