0

I want to do something I thought was pretty basic using fuelphp Basically I need to use multiple urls with only one controller, and assign each different route a default parameter (a cat id for that matter)

For instance in my Listing controller I want to use 2 different routes :

/bags
/accessories

to each of which would be assigned it's cat id

Can't seem to find any easy way to do it in fuelphp...

titiyoyo
  • 911
  • 1
  • 11
  • 28

1 Answers1

2

You can specify a route like 'path/here/(:segment) => 'controller/cat/$1 which will then pass the segment captured in the route as the first parameter to a method called action_cat in the controller class.

This behaviour is pretty well outlined in the documentation http://fuelphp.com/docs/general/routing.html

Emlyn
  • 852
  • 6
  • 16
  • Sorry I wasn't very clear in my question. I am aware of that behavior. My problem is that I don't want to use a (:segment) param. I wantto be able to route urls like 'http://example.com/we-make-wonderful-bags' and 'http://example.com/we-also-make-wonderful-leather-socks' to the same controller, assigning each of them a different cat id like 'controller/cat/1' and 'controller/cat/2'. My tests weren't ok on that. Thanks for your answer anyway mate – titiyoyo Sep 09 '14 at 13:21
  • If you want you can also use closures/anonymous functions to return different destination uris. – Emlyn Sep 09 '14 at 18:04
  • Sorry, forgot the relevant link to the docs http://fuelphp.com/docs/general/routing.html#/inline_routes – Emlyn Sep 09 '14 at 18:14
  • yes it works this way, but I thought there would have been a much simpler and straightforward way to it. Anyway it's done, thanks – titiyoyo Sep 09 '14 at 20:14
  • Last thing I need is to know how to retrieve the parameters I've put in the request, from inside the controller. $this->params(), \Input::get \Input::post don't get me a thing... My final route looks like that: 'bags' => function () { return \Request::forge('front/listing')->execute(array("catId" => "1")); } – titiyoyo Sep 09 '14 at 23:33
  • Your route closure does not have to forge the request, it's better to have it return the UI where it should go. But in regards to the parameters, If you have a controller called `Welcome` and a route that ends up as `welcome/index/123` the action can have a parameter. `public function action_index($id)`. `$id` would be `123` in this case. – Emlyn Sep 10 '14 at 12:52
  • Glad you got it sorted! – Emlyn Sep 10 '14 at 20:39