简体   繁体   中英

Reversing controller argument order in routes file fuelphp

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM