-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Conversation
Could you by any chance give a prolonged example ? |
@macnibblet Sure, take for instance the following route configuration. It will force all shop routes (both the parent and all subsequent children) to use the HTTPS scheme: array(
'routes' => array(
'shop' => array(
'type' => 'literal',
'options' => array(
'route' => '/shop',
'defaults' => array(/* … */)
),
'chain_routes' => array(
array(
'type' => 'scheme',
'options' => array(
'scheme' => 'https'
)
)
),
'may_terminate' => true,
'child_routes' => array(
'products' => array(
'type' => 'segment',
'options' => array(
'route' => '/product/:productId',
'defaults' => array(/* … */)
)
)
)
)
)
); |
Additional information via IRC discussion:
|
Would it be possible to add a segment such as versioning on a API ? return array(
'router' => array(
'routes' => array(
'api' => array(
'type' => 'hostname',
'options' => array(
'route' => 'api.domain.com',
),
'chain_routes' => array(
array(
'type' => 'scheme',
'options' => array(
'scheme' => 'https'
)
),
array(
'type' => 'segment',
'options' => array(
'route' => '/v:version/',
'constraints' => array(
'version' => '\d+'
)
)
)
),
'may_terminate' => false,
'child_routes' => include __DIR__ . '/routes.php'
)
)
)
); |
Yeah @macnibblet, that is one of the use cases :) |
@DASPRiD It looks straight-forward, but I see some potential for repetition (different top-level paths needing the same scheme and/or hostname route). I'd be interested in a solution that allows specifying existing named routes in the |
@weierophinney: This sounds kina tricky. What exactly do you have in mind there? Should one be able to define "prototype" routes, which can be references there, or would you want to be able to reference existing routes? |
@DASPRiD Reference existing routes. This allows defining once, as well as On Tuesday, March 26, 2013, Ben Scholzen wrote:
Matthew Weier O'Phinney |
I like this example you did, @DASPRiD - https://gist.github.com/DASPRiD/2f2544eb4b6539fcca0b 👍 |
@DASPRiD If you can get some tests in, I'm good with this, and will schedule for 2.2.0. |
Unit tests added, ready for merge. |
Yay! |
Can you reference chained routes such as is required in the url view helper and zend navigation route key? You say in your example only a single child? |
|
||
foreach ($this->routes as $key => $route) { | ||
$chainOptions = $options; | ||
$chainOptions['has_child'] = ((isset($options['has_child']) ? $options['has_child'] : false) || $key !== $lastRouteKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. Please break it into multiple lines.
@tomshaw I don't really understand your question. |
- Broke one statement into two for readability - Alphabetize invokables list - CS fixes (commas after all array items)
Thanks @weierophinney for incorporating the changes, as I'm quite busy with $-work right now :) |
Merged to develop for release with 2.2.0. |
@weierophinney GitHub complains about unmerged commits. What is this about? |
@DASPRiD I merged to develop, not master, as it's a new feature. That's why it's complaining. |
Is it possible to use chains and children at the same time? I don't get this example to work. expected: http://www.domain.tld/foo/product/c3po TreeRouteStackTest:
|
I am having the same issue as @tommyseus. I tried to secure the ZfcUser routes with the following: return array(
'router' => array(
'routes' => array(
'zfcuser' => array(
'route' => '/user',
'type' => 'Literal',
'chain_routes' => array(
array(
'type' => 'scheme',
'options' => array(
'scheme' => 'https'
)
)
)
),
),
),
); When echo'ing the route through the URL helper, I get:
|
Site links: http://test.scampaigns.com/Frontend/index Number 1 is working, number 2 is giving 404 error. The problem is with HTTP the site is working fine. but with HTTPS only the default controller is working but other controllers are not working with the https: Below is my module.config.php return array( |
This new route type allows to glue multiple routes together under a single route. This allows to address them with a single name. Common use-cases are:
Here is a simple example of how the feature can be used:
The chains are processed in FIFO order. In the above example, the 'login' route may also have child_routes, in which case the base route of that branch becomes the combined chain of the literal and the scheme route.
The route and factory is designed that way that it allows other modules to easily add conditions (like HTTPS) on a login route without changing the assembling structure.
This PR is so far feature complete, but yet lacks unit tests.