Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Make identifier name configurable for AbstractRestfulController #4181

Conversation

weierophinney
Copy link
Member

Currently, AbstractRestfulController::getIdentifier() hard codes a lookup on an id parameter in either the route matches or the query string. This is not optimal in the case of child resources, as it forces the creation of additional routes to ensure that the :id segment is specific to the given child resource:

'parent' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '/api/parent[/:id]',
    ),
),
'child' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '/api/parent/:parent/child[/:id]',
    ),
),

versus the more semantic:

'parent' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '/api/parent[/:parent]',
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'child' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/child[/:child]',
            ),
        ),
    ),
),

This PR makes the identifier name configurable. BC is retained, as it still defaults to "id"; however, new methods allow you to inject an alternate identifier name, and that name will be used by getIdentifier() in order to look up the resource ID.

- Identifier name defaults to "id"
- Identifier name is mutable
- getIdentifier() uses identifier name to lookup identifier
- Added $identifierName property
- Added mutator and accessor for $identifierName
- Modified getIdentifier() to use the $identifierName when attempting to
  retrieve the resource ID.
@danizord
Copy link
Contributor

danizord commented Apr 4, 2013

👍

mwillbanks pushed a commit that referenced this pull request Apr 4, 2013
…it://github.com/weierophinney/zf2 into feature/4181

Close #4181
mwillbanks pushed a commit that referenced this pull request Apr 4, 2013
@mwillbanks mwillbanks merged commit 121fbda into zendframework:develop Apr 4, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants