日期:2014-05-17  浏览次数:20568 次

codeigniter路由问题
对codeigniter不太熟悉.尤其路由这块.现在改一套系统.自己写的控制器后访问总是出现“route_error”错误;

比方说我写了个login.php控制器放在controllers/admin目录下,我直接访问www.abc.com/admin/login 就会出现“route_error.”错误。
如果我在route.php加上一行:
$route['admin']="admin/login";
这样就可以了。但是太麻烦了,我不可能每写一个控制器就去修改一下route.php吧?!

下面是我的route.php文件。看不懂以前是什么意思,大家帮忙看看怎么设置我才可以正常来写我的控制器而不影响以前的使用:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";

//name-of-school/class-of/firstname-lastinitial/photo-albums/album-name/upload/
$route['([a-zA-Z0-9\-_ ]+)/([a-zA-Z0-9\-_ ]+)/([a-zA-Z0-9\-_ ]+)/(video|photo)\-([a-zA-Z0-9\-_ ]+)/([a-zA-Z0-9\-_ ]+)/([a-zA-Z0-9\-_ ]+)(/([a-zA-Z0-9\-_ ]+))*'] = "user/$4_$5/$7/$8";

$route['([a-zA-Z0-9\-_]+)/school_admin/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)(/([a-zA-Z0-9\-_]+))*'] = "school_admin/$3/$4$5";

$route['([a-zA-Z0-9\-_]+)/group_admin/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)(/([a-zA-Z0-9\-_]+))*'] = "group_admin/$3/$4$5";


//name-of-school/class-of/firstname-lastinitial/games/game-name/
$route['([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)(/([a-zA-Z0-9\-_]+))*'] = "user/$4/$5/$6";


//logout
$route['(logout|login|register)'] = "member/$1";

//404
$route['(games|video-albums|photo-albums|group|admin|groupadmin|yearbook|settings)(/.*)*'] = "error";


------解决方案--------------------
www.abc.com/index.php/admin/login
------解决方案--------------------
queryphp 框架路由可以使用名字


其它设置 可以添加自己定义的路由规则:
C("router")->ruleMaps('logout','/logout', array('controller' => 'auth', 'action' => 'logout'));
C("router")->ruleMaps('signup','/signup', array('controller' => 'auth', 'action' => 'signup'));
C("router")->ruleMaps('profile','/profile/:action', array('controller' => 'profile')); // will call controller "Profile" with dynamic method ":action()"
C("router")->ruleMaps('users','/users/:id', array('controller' => 'users'), array('id' => '[\d]{1,8}')); // define filters for the url parameters


http://code.google.com/p/queryphp/downloads/list