简体   繁体   English

Codeigniter URL结构

[英]Codeigniter URL structure

I would like to implement the following url structure over the codeigniter 我想在codeigniter上实现以下url结构

http://client.xyz.com/division/controller/controller_fuction

Will you please let me know how can i change the route file to meet my requirement. 您能告诉我如何更改路由文件以满足我的要求吗? Thanks. 谢谢。

Comment - 评论-

I would like to setup client wise sepearate database and 'division' may be like division1, division2. 我想设置客户端明智的独立数据库,“部门”可能像部门1,部门2。 Depend on the url setting and session would be loaded. 取决于URL设置和会话将被加载。

set in the config file 在配置文件中设置

$config['index_page'] = '';

then apply htacess 然后申请

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js)
RewriteRule ^(.*)$ ./index.php/$1 [L]

this way you can do like http://client.xyz.com/division/controller/controller_fuction 这样,您可以像http://client.xyz.com/division/controller/controller_fuction

OR you can use Routing 或者您可以使用路由

You need to create your own route class, CI lets us to replace or extend it's core functionality. 您需要创建自己的路由类,CI使我们可以替换或扩展其核心功能。 Just create eg 只需创建例如

class MY_Router extends CI_Router
{
   //so on ..
}

Then save it in application/core folder, then CI will using your Class instead of default. 然后将其保存在application/core文件夹中,然后CI将使用您的Class代替默认值。

look ? 看? http://ellislab.com/codeigniter/user-guide/general/core_classes.html http://ellislab.com/codeigniter/user-guide/general/core_classes.html

You can create MY_Controller which will extend CI_Controller. 您可以创建将扩展CI_Controller的MY_Controller。
Every other controller will extend MY_Controller. 其他所有控制器都将扩展MY_Controller。
Then in MY_Controller you can use this in constructor. 然后在MY_Controller中,您可以在构造函数中使用它。

$controller = $this->uri->segment(1);
$controller_function = $this->uri->segment(2);

Here you can define $devisions or get it from config. 在这里,您可以定义$ devisions或从config中获取它。

$division1  =   array('controller1','controller2','controller3');
$division2  =   array('controller4','controller5','controller6');
$division3  =   array('controller7','controller8','controller9');


if(in_array($controller,$division1)){
    //do blah blah
}else if(in_array($controller,$division2)){
    //do other blah blah
}else{
    //do last and final blah blah
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM