[英]Reversing controller argument order in routes file fuelphp
I am running a fuelphp app with a route that looks like this: 我正在运行带有如下所示路线的fuelphp应用程序:
'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. 不幸的是,发生的是
$firstname
变量包含从路由传入的:lastname
,而$lastname
变量包含从路由传入的:firstname
。
I've tried switching around the $2
and $1
from the routes file. 我试过从路由文件切换
$2
和$1
。
I'd like to keep the endpoint url untouched - I'd just like to reverse the argument order coming in to the controller method. 我想保持端点url不变-我只想反转进入controller方法的参数顺序。
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. 另一种方法是在控制器中使用
$this->param('firstname')
等,而不是将它们作为参数传递给动作函数。
http://fuelphp.com/dev-docs/general/routing.html#/advanced http://fuelphp.com/dev-docs/general/routing.html#/advanced
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.