0

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.

Sworup Shakya
  • 1,328
  • 3
  • 16
  • 44

1 Answers1

3

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

Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63
  • Here's my problem: Let's say I have code that says
    $route['admin/deactivate/(:num)'] = "auth/$1";
    And I want to access 'admin/deactivate/' I can't.
    – Sworup Shakya Jul 12 '12 at 09:55
  • Have you actually tried changing it to `$route['admin/(:any)'] = "auth/$1";` ? – Kemal Fadillah Jul 12 '12 at 09:57
  • Yes, I have. I guess the only way to do this would be writing numerous Routes configs. I was wondering if there's a way to avoid or maybe use some regular expression to dynamically match that. – Sworup Shakya Jul 12 '12 at 10:00
  • Also I am not doing $route['admin/(:any)'] = "auth/$1"; because I already have a admin controller. I want the above specific requests to redirect to go to auth controller and rest would go to admin controller. – Sworup Shakya Jul 12 '12 at 10:04