Codeigniter URL结构

时间:2013-09-27 11:25:57

标签: php codeigniter-2 codeigniter-url

我想在codeigniter上实现以下url结构

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

请您告诉我如何更改路径文件以满足我的要求。感谢。

评论 -

我想设置客户端智能的sepearate数据库,'division'可能就像division1,division2。取决于网址设置和会话将被加载。

3 个答案:

答案 0 :(得分:1)

在配置文件中设置

$config['index_page'] = '';

然后申请htacess

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

这样你可以像http://client.xyz.com/division/controller/controller_fuction

那样做

OR  你可以使用路由

答案 1 :(得分:0)

您需要创建自己的路由类,CI允许我们替换或扩展它的核心功能。只需创建例如

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

然后将其保存在application/core文件夹中,然后CI将使用您的类而不是默认值。

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

答案 2 :(得分:0)

您可以创建扩展CI_Controller的MY_Controller 每个其他控制器都会扩展MY_Controller 然后在MY_Controller中,您可以在构造函数中使用它。

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

您可以在这里定义$ devisions或从配置中获取。

$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
}
相关问题