ZF2: wildcards in routing not filled with url vie helper and controller plugin

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2: wildcards in routing not filled with url vie helper and controller plugin

Ralf Eggert
Hi,

typing this with my one year old daughter on my lap. so only short
descriptions. this route is given:

------------------------------------------------------------------
'application' => array(
    'type'    => 'segment',
    'options' => array(
        'route'    => '[/:locale[/:controller[/:action[/:id]]]]',
        'constraints' => array(
            'locale'     => '[a-z]{2}',
            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'         => '[0-9]+',
        ),
        'defaults' => array(
            'controller' => 'application',
            'action'     => 'index',
            'locale'     => 'de',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'default' => array(
            'type'    => 'Wildcard',
            'options' => array(
            ),
        ),
    ),
),
------------------------------------------------------------------

use the view helper:

<?php
echo $this->url('application', array('controller' => 'user', 'action' =>
'activate', 'id' => 1, 'foo' => 'bar'), array(), true);
?>

use the controller plugin:

echo $this->url()->fromRoute('application', array('controller' =>
'user', 'action' => 'activate', 'id' => '1', 'foo' => 'bar'), array(),
true);

output for both:

/de/user/activate/1

expected output should be:

/de/user/activate/1/foo/bar

bug or feature?

regards,

ralf
Reply | Threaded
Open this post in threaded view
|

Re: ZF2: wildcards in routing not filled with url vie helper and controller plugin

Ben Scholzen 'DASPRiD'
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: ZF2: wildcards in routing not filled with url vie helper and controller plugin

Ralf Eggert
Hi Ben and Matt (who sent me a PM),

> echo $this->url()->fromRoute('application/default', array('controller' =>
> 'user', 'action' => 'activate', 'id' => '1', 'foo' => 'bar'), array(),
> true);

Thanks for explaining it. This makes a lot of sense, unfortunately this
isn't documented yet.

The only problem I have now is that I always need to set the id segment
of the main route. When I set no id but a wildcard option I get a
'Missing parameter "id"' error thrown in

/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Http/Segment.php:259

If I understand it correctly, child-routes can be defined parallel. But
I think I will strip the id segment from my route and let the wildcard
child-route handle ids as well...

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: ZF2: wildcards in routing not filled with url vie helper and controller plugin

Ben Scholzen 'DASPRiD'
CONTENTS DELETED
The author has deleted this message.