CI静态D / C / M路由和URI参数

时间:2012-01-11 22:49:54

标签: codeigniter-2

我有点棘手,我甚至不确定CI的设计是否符合这种方式。

我有一个子域名,我们称之为test.warren.com

test.warren.com指向CI index.php,它与访问warren.com时加载的主index.php是分开的。

根据CI评论

,test.warren.com的index.php定义了静态路由
/*
 * --------------------------------------------------------------------
 * DEFAULT CONTROLLER
 * --------------------------------------------------------------------
 *
 * Normally you will set your default controller in the routes.php file.
 * You can, however, force a custom routing by hard-coding a
 * specific controller class/function here.  For most applications, you
 * WILL NOT set your routing here, but it's an option for those
 * special instances where you might want to override the standard
 * routing in a specific front controller that shares a common CI installation.
 *
 * IMPORTANT:  If you set the routing here, NO OTHER controller will be
 * callable. In essence, this preference limits your application to ONE
 * specific controller.  Leave the function name blank if you need
 * to call functions dynamically via the URI.
 *
 * Un-comment the $routing array below to use this feature
 *
 */
    // The directory name, relative to the "controllers" folder.  Leave blank
    // if your controller is not in a sub-folder within the "controllers" folder
    $routing['directory']   = 'subdir';

    // The controller class file name.  Example:  Mycontroller
    $routing['controller']  = 'testcontroller';

    // The controller function you wish to be called.
    $routing['function']    = 'testmethod';

现在这一切都很有效 - 我有我的单方法网站。没有其他东西可以访问;只有那种方法。如果我去test.warren.com - 我得到testmethod()执行的任何内容。

现在,我不能做的部分 - 传递URI参数 EG:test.warren.com/param1/param2/param3 --- 404

据我可以调试这个不起作用的原因是因为当初始化路由器类时,它会尝试检查'param1'是控制器类还是目录;这符合标准CI配置的预期。然后是404s。

我想我可以通过编辑index.php底部加载的主要核心/ CodeIgniter.php来解决这个问题。但是我非常犹豫,因为这个CI安装有多个站点安装。

CI是v2.0.3

有人知道这是否可行?

1 个答案:

答案 0 :(得分:0)

如果您以这种方式使用“默认路线”,则需要设置辅助路线以通过参数。

$route['(:any)/(:any)/(:any)'] = 'controller/action/$1/$2/$3';

这个“应该”工作,为了匹配它,你必须传递三个参数,如果你没有传递三个,它将恢复到默认控制器或404(如果只传递一个或两个。)< / p>

希望有帮助吗?