Bug Report #4681

Route::url() says param is required when it's not

Added by Ihor Chumachenko over 1 year ago. Updated over 1 year ago.

Status:ClosedStart date:12/20/2012
Priority:NormalDue date:
Assignee:Lorenzo Pisani% Done:

0%

Category:-
Target version:3.3.1
Resolution:duplicate Points:1

Description

I have a route:

Route::set('module', '<controller>(/<type>(/<entity>))(/<action>(/<id>))', array(
    'controller' => 'blog|messageboard',
    'type' => 'committee|group|user',
    'entity' => '[0-9]+',
))
->defaults(array(
    'action' => 'index',
));

Now i calls:

Route::url('module', array(
    'controller' => 'blog',
    'type' => 'committee',
    'entity' => NULL,
    'id' => NULL,
))

And instead of '/blog/controller' the exception 'Required route parameter not passed: id' in https://github.com/kohana/core/blob/3.3/master/classes/Kohana/Route.php at line 568 is rised.

If I remove '(/<id>)' from the route everything works fine.


Related issues

Duplicates Kohana v3.x - Bug Report #4630: Optional route params become required Closed 10/24/2012

History

#1 Updated by Ihor Chumachenko over 1 year ago

It seems I've got the problem. The code

534        // Keep track of whether an optional param was replaced
535        $provided_optional = FALSE;
536
537        while (preg_match('#\([^()]++\)#', $uri, $match))
538        {
539
540            // Search for the matched value
541            $search = $match[0];

should be changed by this:

534        while (preg_match('#\([^()]++\)#', $uri, $match))
535        {
536            // Keep track of whether an optional param was replaced
537            $provided_optional = FALSE;
538
539            // Search for the matched value
540            $search = $match[0];

#2 Updated by Ihor Chumachenko over 1 year ago

Oops. I'm sorry. Previous post was wrong. Of course $provided_optional = FALSE; should stay before the while. Current code doesn't suppose to meet (...)(...) in the route.

#3 Updated by Thomas Lété over 1 year ago

I have the same problem here, nested route parameters seem to fail with Kohana 3.3...

#4 Updated by Lorenzo Pisani over 1 year ago

  • Status changed from New to Closed
  • Assignee set to Lorenzo Pisani
  • Target version set to 3.3.1
  • Resolution set to duplicate

was fixed by #4630

Also available in: Atom PDF