CodeIgniter Forums
Routing optional paremeter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Routing optional paremeter (/thread-18259.html)



Routing optional paremeter - El Forum - 04-30-2009

[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


Routing optional paremeter - El Forum - 04-30-2009

[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!


Routing optional paremeter - El Forum - 04-30-2009

[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.


Routing optional paremeter - El Forum - 06-09-2011

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

I have the same situation how do you do it.

Thanks in advance