Hi,

I'm just starting out with ZF trying to shoehorn it into an older
product as we start to (slowly) reimplement it based on a more robust
design (I know that it should really be ripped right out and we should
start again but sadly that just wont happen!).

Anyway, I'm using Zend_Controller_Router_Route_Regex, and have found
some odd behaviour that I'm not 100% sure is deliberate and wonder if
someone could confirm this is expected or if it's actually a bug!

Say I have a regexp route along the lines of:

$route = new Zend_Controller_Router_Route_Regex(
      '(mytype|othertype)/(\d+)(/.*)?',
      array(
        'module' => 'Blah',
        'controller' => 'Blah',
        'action' => 'Blah'
      ),
      array(
        1 => 'type',
        2 => 'id',
        3 => 'path'
      )
    );

The above code should match the following URLs

1) /mytype/123
2) /othertype/123
3) /mytype/123/
4) /mytype/123/wibble


The variables will be:

type:
1) mytype
2) othertype
3) mytype
4) mytype

id:
1) 123
2) 123
3) 123
4) 123

so far so good but here is where it get's odd.

path:
1) NULL (good)
2) NULL (good)
3) NULL (hmmmmmm??? I'd expect "/")
4) /wibble (good)


So my question is, why is the case three not returning my expected value
of "/".

Is this perhaps my a problem with my PCRE version (7.6)? Or PHP version
(5.2.5)? My ZF version (1.5.1)? Or is this actually expected?


The reason I want this is that if I find "path" to be empty I want to
append a trailing slash to it and redirect to allow for relative
hyperlinks to work properly (this is legacy code remember). I can do
this in my controller by doing something like:

if (empty($this->_getParam('path'))
    && '/' != substr($this->getRequest()->getRequestUri(), -1))
{
  // Redirect.
}

but this seems like a hack/workaround.

Am I missing something?

Cheers

Col

Reply via email to