0

I am running a fuelphp app with a route that looks like this:

'lastname/:lastname/firstname/:firstname'=> '(@api)/mycontroller/my_method/$2/$1',

And then I have a method on my controller like this:

public function get_my_method($firstname, $lastname);

Unfortunately, what happens is the $firstname variable contains the :lastname passed in from the route, and the the $lastname variable contains the :firstname passed in from the route.

I've tried switching around the $2 and $1 from the routes file.

I'd like to keep the endpoint url untouched - I'd just like to reverse the argument order coming in to the controller method.

Anyone know how to accomplish this?

johncorser
  • 9,262
  • 17
  • 57
  • 102
  • Switching $firstname and $lastname in method itself? – Tpojka May 19 '15 at 19:17
  • Can't do this. I am defaulting $lastname to null and other routes are calling the controller without the $lastname field set. I could check for last name and swap, but I'd have to do that in every controller method, get, post, put, delete. Other parts of the application would need to be refactored as well, such as traits that would no longer apply generally would have to implement the shared get_my_method in each class with a nullable $lastname – johncorser May 19 '15 at 19:31

1 Answers1

1

You need to wrap the segments in brackets to capture them rather than using named parameters.

'lastname/(:segment)/firstname/(:segment)' => '(@api)/mycontroller/my_method/$2/$1'

The alternative is to use $this->param('firstname'), etc, in your controller rather than having them passed as arguments to the action function.

http://fuelphp.com/dev-docs/general/routing.html#/advanced

Emlyn
  • 852
  • 6
  • 16