CodeIgniter Forums

Full Version: Routing optional paremeter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Jagar[/eluser]
How can I make a parameter optional in routing.

For example I have the following link
Code:
admin/admin_manage/index/(optional param}

into this
Code:
admin/manage/(optional param)

I'm doing the following:
Code:
$route['admin/manage/?(:any)'] = 'admin/admin_manage/$1';
but does not work

Thanks

El Forum

[eluser]Jagar[/eluser]
I'm using
Code:
$route['admin/manage/?(.*)'] = 'admin/admin_manage/index/$1';

and in my index function i have a parameter function index($sortby='id') which is optional, that will be used if nothing is there.

But with that routing code, it seem to delete the default param for function index.

Any ideas?

Thanks for any help!

El Forum

[eluser]Jagar[/eluser]
I got it working and may not be the best way.

In my function where I receive the sort by, I check if the field exist and if it exist. If any of those are false, then I set to default.

El Forum

[eluser]Miguel Diaz[/eluser]
Hi Jagar,

I have the same situation how do you do it.

Thanks in advance