On Wed, Dec 4, 2013 at 7:13 AM, Mucahit Sancar Kahveci
<[email protected]> wrote:
> Hello I have a concern about mvc routing wildcard.
>
> I am trying to use a route as in default route zf1 as follows:
> website.com/controller/action/param1/value1/..../paramn/valuen/
>
> It is fine using the below described routes without the trailing slash. But 
> when the trailing slash is added it does not matches a route. The description 
> of the route as follows (i try to describe this way instead of all array 
> elements):
> route:
> 0. segment: /[:controller[/:action]]
>         child routes:
>         0. wildcard
>                 child routes:
>                 0. literal: '/'
>
> So I thought adding the literal '/' child route to the wildcard child route 
> may cause it to match one but it did not. However it did solved the same 
> trailing slash problem when used as a child route after segment: 
> /[:controller[/:action]] route
> 0. segment: /[:controller[/:action]]
>         child routes:
>         0. literal '/'
> Above settings solved the problem of trailing slash in the below address:
> website.com/controller/action/
>
> Then I have checked the source code and find out that it is the below code at 
> Zend\Mvc\Router\Http\Wildcard.php on line 123 within the match method (ZF 
> version: 2.2.5) that causes the problem:
> L121    $params  = explode('/', $path);
> L122
> L123    if (count($params) > 1 && ($params[0] !== '' || end($params) === '')) 
> {
> L124        return null;
> L125    }
>
>
> It explodes the path with the '/', and since the last $params element is '', 
> it returns null. Since the wildcard route does not accepts any of the valid 
> $params and the valid route, the wildcard route is cancelled before it can 
> check the child routes which is the literal '/' in this case.
> If i remove the
>
> || end($params) === ''
> part on line 123 at above code the app seems to work good.
>
>
> Please tell me if this is a bug or should it be in that way to work properly. 
> And if this is a bug, will this be fixed with next update.

This is a _limitation_ of the wildcard route, and not a _bug_.

Wildcard routes are, pardon the pun, wildly problematic when it comes
to matching, and should never have child routes, as they are greedy
and look to the end of the path.

I'd argue you should never use the wildcard route. If you need
arbitrary parameters as part of the request, use the query string
instead.


-- 
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