代码igniter可选参数 [英] Code igniter optional parameter

查看:76
本文介绍了代码igniter可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用CI中的路由创建注册表单

I'm trying to use routing in CI to create a signup form

注册已重新路由用户/注册

但是我的注册函数可以包含一个参数: $ type = 1)

But my signup function can contain a paramater: function signup($type = 1)

如何通过路由选择?我试过 $ route ['signup /?(:num)'] ='user / signup / $ 1'; ,但是当去 我得到一个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";

这篇关于代码igniter可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆