kohana3.3 Route::url() not working very well

135 Views Asked by At

```

route setting:

Route::set('home', '(<action>)(_<p>.htm)', 
           array(
               'action' => '(movie|tv|new)', 
               'p' => '[2-9]|[1-9][0-9]+'
           )
)->defaults(
           array(
               'controller' => 'Home', 
               'action' => 'index', 
               'p' => 1
           )
);

get a url by Route::url():

Route::url('home',array('action' => 'movie', 'p' => 3));

got a url:

http:// www.domain.com/movie_3.htm

working very well.

but

Route::url('home',array('action' => 'movie'));

got a url:

http:// www.domain.com/movie_1.htm 

this is not right .

it should be:

http:// www.domain.com/movie/ 

```

how can i fix it ????

thanks.

=====update 8/19 16:23 =====

Route::set('test', 'movie(_<p>.htm)', 
                array('p' => '[2-9]|[1-9][0-9]+')
          )->defaults(
                array('controller' => 'Movie', 'action' => 'index', 'p' => '1')
          );

this route setting works well in any situation

Route::url('test',array('p'=>'1'));

got a url:

http://www.domain.com/movie

Route::url('test',array('p'=>'2'));

got a url:

http://www.domain.com/movie_2.htm

Route::url('test');

got a url:

http://www.domain.com/movie

= =,is there a bug in kohana core ???

1

There are 1 best solutions below

5
On

I think you should remove "p" parameter from defaults and validators. So your code should looks like this:

Route::set('home', '(<action>)(_<p>.htm)', 
           array(
               'action' => '(movie|tv|new)'
           )
)->defaults(
           array(
               'controller' => 'Home', 
               'action' => 'index'
           )
);

I am not pretty sure about removing p from defaults so you can try to add it back