On Wed, Aug 7, 2013 at 12:09 PM, Philip G <[email protected]> wrote:
> Afternoon Matt, and ZFW List. I'm back to this.
>
> I have it working, almost. I get it now, but I'm running into a problem
> with the path child route: it's not working. When ever I add a path, or
> additional resource key, it fails:
>
> /a/2.1/route/cntl -> works.
> /a/2.1/route/cntl/name -> works
> /a/2.1/route/cntl/a/resource/path.jpg -> fails -- Error: The requested URL
> could not be matched by routing.
>
> Oddly enough, I overloaded Segment::match() and I see a RouteMatch
> returning. Not sure why it's failing after that.
>
> I've even shortened it to:
>
> 'type' => 'segment',
> 'options' => array(
> 'route' => '/a/:version/route/:controller',
> 'criteria' => array(
> 'version' => '\d+\.\d+',
> 'controller' => '[a-z][\w]+',
> ),
> ),
> 'may_terminate' => true,
> 'child_routes' => array(
> 'path' => array(
> 'type' => 'segment',
> 'options' => array(
> 'route' => '/:resource',
> ),
> ),
> ),
>
>
> It works with case 1 and 2, but fails with case 3.
>
After much deliberation and code tracing (and testing), I have discovered a
hidden feature of Segment that isn't documented anywhere: delimiter. ...
Okay, so it is talked about, but more briefly highlighted.
If you pass in a value within { and } it will use that as a delimiter break
to stop a hungry regex. Without it, /:resource becomes /(?P<param1>[^/]+) which
is bad because I need everything in the path. However, I discovered if I
use /:resource{?} the regex becomes: /(?P<param1>[^?]+) -- Exactly what I'm
after: Everything until the query string.
New child route looks like so, and it works:
'child_routes' => array(
'path' => array(
'type' => 'segment',
'options' => array(
'route' => '/:resource{?}',
),
),
),
---
Philip
[email protected]
http://www.gpcentre.net/