子域导致codeigniter控制器? [英] Subdomains leading to Codeigniter Controllers?

查看:244
本文介绍了子域导致codeigniter控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个普遍的要求,但我一直没能找到做这样的事情明确的说明。

This seems like a common request, but I haven't been able to find definitive instructions on doing something like this.

我想一个子域触发我的CI安装一定的控制。例如:

I'd like a subdomain to trigger a certain controller on my CI installation. For example:

students.mysite.com :将打开 mysite.com/students (技术上: mysite.com/index.php/students 控制器:学生

students.mysite.com : would open mysite.com/students (technically: mysite.com/index.php/students. controller: students)

teachers.mysite.com :将打开 mysite.com/teachers

而更深层次遍历时preserving的子域。例如:

While preserving the subdomain when traversing deeper. For example:

students.mysite.com/help :将打开 mysite.com/students/help 控制器学生() 方法帮助()

students.mysite.com/help/contact :   将打开的 mysite.com/students/help/contact 控制器学生()方法的<强>帮助(),参数联系人

students.mysite.com/help/contact : would open mysite.com/students/help/contact (controller: students(), method: help(), argument: "contact")

students.mysite.com/help/contact/email :   将打开的 mysite.com/students/help/contact 控制器学生()方法的<强>帮助(),参数联系人,电子邮件

students.mysite.com/help/contact/email : would open mysite.com/students/help/contact (controller: students(), method: help(), arguments: "contact", "email")

我知道 something.mysite.com 现在返回一个错误。所以我想:

I realize that something.mysite.com right now returns an error. So I figure:

第1步将允许 anything.mysite.com 返回根(mysite.com/index.php)

Step 1 would be allowing anything.mysite.com to return the root (mysite.com/index.php)

第2步将读取该子域,并呼吁该控制器

Step 2 would be reading the subdomain and calling that controller

第3步将读取第一个参数后的第一个/,并呼吁该控制器的方法,并通过剩余的URL部分作为参数

Step 3 would be reading the first argument after the first "/" and calling that method of the controller, and passing the remaining url parts as arguments

我想我真的很为难位于第1步。我在一个共享的托管帐户,这事我可以通过的cPanel 吗?我尝试添加一个子域的 *。mysite.com 没有任何的运气(除非我只需要等待更长的时间传播史,但我觉得机会是较高的,我听错了)。

I guess really I'm stumped at Step 1. I'm on a shared hosting account, is this something I can do via CPanel? I tried adding a subdomain for *.mysite.com without any luck (unless I just needed to wait longer for propogation, but I feel the chances are higher that I got it wrong).

回到我的家WAMP的安装,我会改变了httpd.conf中,对不对?我可以acheive没有修改该文件这样的效果(因为我可能做不到,因为我使用webhostinghub.com共享)

Back on my home WAMP installation, I'd change up httpd.conf, right? Can I acheive this effect without modifying that file (since I probably can't, since I'm shared using webhostinghub.com)

呼,感谢您的时间! - 基思

Phew, thanks for your time! - Keith

推荐答案

当你想使用一个特定的域导致你的控制器,我想出了用的是应用程序/配置/路由.PHP 文件来实现它。这个想法是负载不同的控制器取决于你用​​什么子域,因此,而不是写的路线列表为您的域名,你写的路线取决于你访问该域名的列表:

As you want to use a particular domain to lead to your controllers, what I came up with was using the application/config/routes.php file to achieve it. The idea is load different controllers depending on what subdomain you use, so, instead of writing a list of routes for your domain, you write a list of routes DEPENDING on the domain you're accessing from:

switch ( $_SERVER['HTTP_HOST'] ) {
    case 'students.mysite.com':
        $route['default_controller'] = "students";
    break;
    case 'teachers.mysite.com':
        $route['default_controller'] = "teachers";
    default:
        // The list of your $routes lines at is was...
    break;
}

要完成这项工作,你只需要在子域名指向你的CI项目(德韦恩Towell在对方回答的第1步介绍了如何做完美的),你就会有一切工作,你的共享托管亿韩元 T为一个问题,你会不会来配置服务器。

To make this work, you only have to point the subdomain to your CI project (Dwayne Towell in the step 1 of the other answer explains how to do it perfectly) and you'll have everything working, your shared hosting won't be a problem and you won't have to configure the server.

这篇关于子域导致codeigniter控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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