2012-04-20 60 views
0

所以管理平台有我观察了很奇特的URL映射风格:codeigniter中的自定义URL映射像redmine?

http://demo.redmine.org/projects/<project-name>/controller/action 

样本:

http://demo.redmine.org/projects/produto/activity 
http://demo.redmine.org/projects/produto/issues/new 
http://demo.redmine.org/projects/produto/issues/gantt 
http://demo.redmine.org/projects/produto/files 

和URL变化的项目变更。

我该如何在codeigniter中做到这一点?我认为它可以用routes.php完成,但到目前为止我无法获得任何地方。

寻找任何帮助。谢谢。

回答

0

添加到您的routes.php文件(顺便说一句:你需要URL重写了启用路由的工作,即使用.htaccess

$route['projects/(:any)/(:any)/(:any)'] = "$2/$3/$1"; 

例如/projects/produto/issues/new将调用新的功能在类问题,它传递参数“produto”

还要检查http://codeigniter.com/user_guide/general/routing.html

2

您使用路由文件中的application/config/routes.php文件 你会使用这样的:

// the $1 maps to :any 
$route['projects/produto/:any'] = "$1"; 

// the $1 maps to the first any, $2 maps to the second :any 
$route['projects/produto/:any/:any'] = "$1/$2"; 

如果您正在处理干净的URL,则需要启用mod_rewrite。否则,期待index.php/controller/action。我不能在那里自己测试,但你应该参考:

一旦你添加一个路由(它必须在配置中被称为$ route []),刷新页面并尝试去URL!

http://codeigniter.com/user_guide/general/routing.html

+0

在您的exmaples控制器操作不知道哪个项目被选中! – 2012-04-20 22:27:12

+0

你可能必须在硬编码它..否则你可以尝试... $ route ['projects /:any /:any'] =“$ 1/$ 2”; – JREAM 2012-04-20 22:30:43

+0

看到我的答案,那可行 – 2012-04-20 22:32:04

3

使用下列功能的 “应用程序/控制器/ projects.php” 控制器内:从数据库中提取他们

public function _remap($method) 
{ 
    if ($method == 'project-name') 
    { 
     //display project1 
    } 
    elseif($method == 'project-name2') 
    { 
     //display project2 
    } 
} 

您可以为不同的方法做同样的

看看这里: http://codeigniter.com/user_guide/general/controllers.html#remapping

你也可以路由你的骗局troller通过使用application/config/routes.php中的自定义路由

$route['example'] = "controller/function"; 
$route['example2/(:any)'] = "controller/function";