CodeIgniter可选参数 [英] CodeIgniter optional parameter
本文介绍了CodeIgniter可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在CI中使用路由创建注册表单
I'm trying to use routing in CI to create a signup form
注册
已重新路由到用户/注册
但是我的注册功能可以包含参数: function signup( $ type = 1)
But my signup function can contain a paramater: function signup($type = 1)
如何通过路由将此选项设置为可选?我试过 $ route ['signup /?(:num)'] ='user / signup / $ 1';
,但是要转到 / signup
我得到404,只有 / signup / 1 /
有效。
How can I make this optional via routing? I tried $route['signup/?(:num)'] = 'user/signup/$1';
, but when going to /signup
I'm getting a 404, only /signup/1/
works.
推荐答案
最简单的表达方式可能是声明两条路径:
The clearest way to express this would probably be to declare both routes:
$route['signup'] = "user/signup";
$route['signup/(:num)'] = "user/signup/$1";
这篇关于CodeIgniter可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文