Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Route and argument capture in controller
  • Hey Harro,
    when I have in route :

    'category' => 'site/index',
    'category/(:category)' => 'site/index/$1',
    'video' => 'site/index',
    'video/(:vimeo)' => 'site/index/$1'


    public function action_index($vimeo = NULL, $category = NULL ) {

    echo "vimeo : ".$vimeo."<br/>";
    echo "category : ".$category;
    }

    I'd would like send the right value to category = "test" when I do : /category/test
    and to vimeo = 32515  when I do :  /vimeo/32515

    It doesn't work, Am i missed something ?

    thanks
  • Yes.

    Routes are processed in order of definition. So "/category/test" is matched by the first rule, not the second. Same is true for the second set (video/...).

    Solution, swap them... ;-) 
  • I did that :

    'video' => 'site/index',
    'category' => 'site/index',
    'video/(:vimeo)' => 'site/index/$1',
    'category/(:category)' => 'site/index/$1',

    but it doesn't work it, I have always $vimeo data, $category is always empty
    for both the requests :
    /video/test
    /category/390939397

    weird
  • aah ok, I changed to

    'video' => 'site/index',
    'category' => 'site/index',

    'video/(:vimeo)' => 'site/index/$1',
    'category/(:category)' => 'site/index//$1',

    work now
    thanks :)
  • I tested this config :

    'video/(:vimeo)' => 'site/index/$1',
    'category/(:category)' => 'site/index//$1',
    'page/(:vimeo)/(:category)' => 'site/index/$1/$2',

    with this request : /page/390939397/test

    I get : 

    vimeo : 390939397
    category : 390939397

    Why ?
  • That doesn't sound logical, I can reproduce it, so I will have to look into that.
  • HarroHarro
    Accepted Answer
    "page/:vimeo/:category" works fine.

    The cause of the problem are the brackets. The Router will convert the named parameters to a regex group, which you place into another group with your brackets. Which causes the segment to be into the result twice.

  • Working fine without brackets, thanks Harro !
    :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion