具有正则表达式含义的codeigniter路由

时间:2018-08-17 03:22:43

标签: php regex codeigniter-3

有人可以根据这些正则表达式的路线给我真实的例子, 与这些正则表达式匹配的示例codeigniter路由,这些路由用于重定向到codeigniter 3控制器:

    $route['(file|image)-([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/$1/$2/$3';
    $route['noimage-([0-9]+)-([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/noimage/$1/$2/$3';
    $route['noimage-([0-9]+)-([0-9]+)'] = 'General/noimage/$1/$2';
    $route['remove-my-file/([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/removeMyFile/$1/$2';
    $route['([a-z]{2})'] = 'General/index/$1'; 
    $route['([a-z]{2})/([A-Za-z\_]+)-index'] = '$2/index/$1';
    $route['([a-z][a-z])/account-setting']= "General/accountSetting/$1";
    $route['([a-z][a-z])/(login|logout)']= "Registration/$2/$1";
    $route['([a-z][a-z])/user-registration/active/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)']= "Registration/activeAccount/$1/$2/$3";
    $route['([a-z][a-z])/set-new-password/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)']= "Registration/setNewPassword/$1/$2/$3";

1 个答案:

答案 0 :(得分:1)

    $route['(file|image)-([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/$1/$2/$3';

    file-01-AB -> General::index('file', '01', 'AB')
    image-02-CD -> General::index('image', '02', 'CD')
##
    $route['noimage-([0-9]+)-([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/noimage/$1/$2/$3';

    noimage-01-02-AB -> General::noimage('01', '02', 'AB')
##
    $route['noimage-([0-9]+)-([0-9]+)'] = 'General/noimage/$1/$2';

    noimage-01-02 -> General::noimage('01', '02')
##
    $route['remove-my-file/([0-9]+)-([A-Za-z0-9\_]+)'] = 'General/removeMyFile/$1/$2';

    remove-my-file/01-AB02 -> General::removeMyFile('01', 'AB02')
##
    $route['([a-z]{2})'] = 'General/index/$1';

    ab -> General::index('ab')
##
    $route['([a-z]{2})/([A-Za-z\_]+)-index'] = '$2/index/$1';

    ab/Cd-index -> Cd::index('ab')
##
    $route['([a-z][a-z])/account-setting']= "General/accountSetting/$1";

    ab/account-setting -> General::accountSetting('ab')
##
    $route['([a-z][a-z])/(login|logout)']= "Registration/$2/$1";

    ab/login -> Registration::login('ab')
    bc/logout -> Registration::logout('bc')
##
    $route['([a-z][a-z])/user-registration/active/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)']= "Registration/activeAccount/$1/$2/$3";

    ab/user-registration/active/aB03/04Dc -> Registration::activeAccount('ab', 'aB03', '04Dc')
##
    $route['([a-z][a-z])/set-new-password/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)']= "Registration/setNewPassword/$1/$2/$3";

    ab/set-new-password/aB03/04Dc -> Registration::setNewPassword('ab', 'aB03', '04Dc')

“(”“)”内部的集合和要在函数中使用的索引,第一个()是$ 1,()的第二个参数是$ 2等...

0-9 means number
a-z lowercase letters
A-Z uppercase letters
+ means more than 1 match
(file|image) means and OR