CodeIgniter:指向具有URL段的函数 [英] CodeIgniter: Directing to functions with a URL segment

查看:163
本文介绍了CodeIgniter:指向具有URL段的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的公司制作一个调查系统,我在系统中设置它,以便有两种方式进行调查。

I'm working on a survey system for my company and I have it setup in the system so that there are two ways to take the survey.

1)新的Survey Taker没有预先信息

1) New Survey Taker no prior information

2)调查已发送并创建了会话。

2)Survey was already sent out and a session was created.

如果我想要我的网址如下所示:

mydomain.com/SurveySystem/index.php/survey/$surveyID

In case one I would like my URL to look like:
mydomain.com/SurveySystem/index.php/survey/$surveyID

($ surveyID是调查的整数)

($surveyID being a integer of the survey to take)

第二种情况是我们创建链接用于测试者。我想要的网址如下所示:

mydomain.com/SurveySystem/index.php/survey/$surveySessionID/$guestID

The second case would where we create a link with for the test taker. I would like the URL to look like this:
mydomain.com/SurveySystem/index.php/survey/$surveySessionID/$guestID

在我的Survey类中,它的设置如下:

In my Survey class I have it setup as the following:

function index(){

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));
}

}

当没有信息传递它回波就好。
但是如果我尝试把一个整数,其中surveyID是它认为我在控制器中加载一个方法。

When no information is passed the it echos just fine. But if I try to put a integer where the surveyID is it thinks i'm loading up a method in the controller.

感谢您的帮助!

推荐答案

使用 URI路由以覆盖默认控制器/函数/参数映射。

Use URI routing to override the default controller/function/arguments mapping.

示例: $ c> application / config / routes.php :

Example: in your application/config/routes.php:

$route['survey/:num'] = "survey/take_suvey";

奖金:您也可以移除索引.php / 部分,请参阅删除index.php文件

Bonus: You can also remove the index.php/ part, see Removing the index.php file.

这篇关于CodeIgniter:指向具有URL段的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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