我正在为我的公司制定一个调查系统,我在系统中进行了设置,以便有两种方式来进行调查.
1)新调查者没有先前的信息
2)调查已经发出并创建了一个会话.
如果我希望我的URL看起来像:
mydomain.com/SurveySystem/index.php/survey/$surveyID
($ surveyID是调查的整数)
第二种情况是我们为考生创建链接.我希望URL看起来像这样:
mydomain.com/SurveySystem/index.php/survey/$surveySessionID/$guestID
在我的Survey课程中,我将其设置如下:
function index(){
$segments = $this->uri->total_segments();
if($segments == 1){
echo "no surveyID set";
return;
}
if($segments == 2){
$this->take_survey($this->uri->segment(2));
}
if($segments == 3){
$this->survey_session($this->uri->segment(3), $this->uri->segment(4));
}
Run Code Online (Sandbox Code Playgroud)
}
当没有信息传递时,它回声就好了.但是,如果我尝试在surveyID中放置一个整数,它认为我在控制器中加载了一个方法.
感谢您的帮助!
使用URI路由覆盖默认的控制器/函数/参数映射.
示例:在您的application/config/routes.php:
$route['survey/:num'] = "survey/take_suvey";
Run Code Online (Sandbox Code Playgroud)
额外奖励:您也可以删除该index.php/部分,请参阅删除index.php文件.