On Fri, Aug 2, 2013 at 6:09 PM, Philip G <[email protected]> wrote:
> How do I work on configuring ZF2 route to work with file path as a
> parameter:
> /a/2.1/route/component/optional/resource/id.jpg
>
> /a/2.1/route - is static. It's always there in the URL for every module
> ever called.
>
> /component/ - is required. It is our component for REST calls. The
> component is to map directly to a controller.
>
> /optional/resource/id.jpg - is an optional file path, that may or may not
> be there.

I'd do this as a set of nested routes:

    'parent' => array(
        'type' => 'segment',
        'options' => array(
            'route' => '/a/:version/route',
            'criteria' => array(
                'version' => '\d+\.\d+',
            ),
        ),
        'may_terminate' => false,
        'child_routes' = array(
            'component' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/:controller',
                    'defaults' => array(
                         'action' => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' = array(
                    'path' => array(
                        'type' => 'segment',
                        'options' => array(
                            'route' => '/:fullpath',
                        ),
                    ),
                ),
            ),
        ),
    ),

Some notes:

- Since the version is clearly necessary, I've made it a required
argument, with criteria.
- The parent route may not terminate; it requires a controller. Which
is the first child in the route.
- The "component" route defines the "controller" as a required
argument. That route is marked as able to terminate, and defines a
default for the action.
- A final child route, "path" has a non-optional "fullpath" argument.
However, since its direct parent can terminate, it is in effect
optional for the purposes of matching.

Hope that makes sense!

>
> my attempts aren't working:
> I've created a route segment, using the AlbumRest examples. route =>
> '/a[/:version]/route/album-rest[/:fullpath]'
>
> However, it only works with one trailing path after "album-rest." As soon
> as I use "/option/resource" it fails.
>
> ---
> Philip
> [email protected]
> http://www.gpcentre.net/



-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to