如何将2个参数路由到控制器? [英] How to route 2 parameters to a controller?
本文介绍了如何将2个参数路由到控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图向控制器中的一个方法发送更多的参数,像这样:
http://localhost/ci/index.php/subjects/3/state
这是我尝试过的路线:
$ route ['subjects /(:num)'] ='subject / view / $ 1';
$ route ['subjects /(:num)/ {:any}'] ='subject / view / $ 1 / $ 2';
方法接受2部分:
public function view($ slug,$ id = null){
}
但我似乎得到一个404.我如何得到这个工作?我需要view方法总是接受1个参数和可选的其他参数。
注意:我包括url帮助。
解决方案
您的路线方括号有问题,只需将其从{}更改为()括号即可工作
来自
$ route ['subjects /(:num)/ {:any}'] ='subject / view / $ 1 / $ 2';
到
$ route ['subjects /(:num)/(:any)'] ='subject / view / $ 1 / $ 2';
This seems really basic but i can't get the hang of it.
I'm trying to send more then one parameter to a method in the controller, like this :
http://localhost/ci/index.php/subjects/3/state
This is the routings i've tried :
$route['subjects/(:num)'] = 'subjects/view/$1';
$route['subjects/(:num)/{:any}'] = 'subjects/view/$1/$2';
the method accepted 2 paremeters :
public function view($slug, $id = null){
}
but i seem to get a 404. How can i get this to work? i need the view method to always accept 1 parameter and optional other parameters.
NOTE : I am including the url helper.
解决方案
you have problem with your route brackets just change it from {} to () brackets will work
from
$route['subjects/(:num)/{:any}'] = 'subjects/view/$1/$2';
to
$route['subjects/(:num)/(:any)'] = 'subjects/view/$1/$2';
这篇关于如何将2个参数路由到控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文