简体   繁体   中英

Codeigniter 2 Routing with undeterminded number of segments/parameters

I am using Codeigniter 2 and am currently using the 'Routers' config file to set the routes. I am also using IonAuth library. I have a code that does something like:

    $route['admin/(login|logout|change_password|forgot_password|reset_password
|activate|deactivate|create_user)'] = "auth/$1";

Now my problem is that, in some of the IonAuth methods, there are none, 1 or 2 parameters. If I try to access the url like:

http://localhost/ion_auth_try/admin/deactivate/1

I get an 404 error.

The signature of the 'deactivate' method is

function deactivate($id = NULL)

I've been trying to solve this for a long time now. I'm stuck.

If I were you, I'd do this instead.

$route['admin/(:any)'] = "auth/$1";

It's much more simpler and it solves the problem perfectly. With the above rule, you can access both admin/some_method and admin/some_other_method/with_a_parameter just fine. However, you should note that if you were to access the page by entering just admin , you'd need to add the following:

$route['admin'] = "auth";

See the doc: http://codeigniter.com/user_guide/general/routing.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM