CodeIgniter Forums
Routing changes at a single location - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Routing changes at a single location (/showthread.php?tid=66390)



Routing changes at a single location - RBX - 10-18-2016

I've recently started using CI and find it really difficult to perform routing changes. Whether I want to specify a form action, or want to redirect to a page, I have to specify some URL fragment, and at a later point, if I decide to make changes to route, I have to find each usage and replace it. How can I avoid doing this?


RE: Routing changes at a single location - d4jk4 - 10-21-2016

(10-18-2016, 12:35 PM)RBX Wrote: I've recently started using CI and find it really difficult to perform routing changes. Whether I want to specify a form action, or want to redirect to a page, I have to specify some URL fragment, and at a later point, if I decide to make changes to route, I have to find each usage and replace it. How can I avoid doing this?

Did you try (:num) and (:any) regexes ?


RE: Routing changes at a single location - RBX - 10-21-2016

(10-21-2016, 03:02 AM)d4jk4 Wrote:
(10-18-2016, 12:35 PM)RBX Wrote: I've recently started using CI and find it really difficult to perform routing changes. Whether I want to specify a form action, or want to redirect to a page, I have to specify some URL fragment, and at a later point, if I decide to make changes to route, I have to find each usage and replace it. How can I avoid doing this?

Did you try (:num) and (:any) regexes ?

I use them, but I don't see how they can help in changing
rewards/cart/(:num)/add to cart/add/(:num).

I've been thinking about 'naming' my routes so I could something like
PHP Code:
$route[ADD_TO_CART'(:num)'] = 'controller/action';
echo 
form_open(ADD_TO_CART.$id); 
but it effectively limits the wildcards to the end of the route.

Edit: I just read a blog post on CI4 which says named routes are coming. I wish some of these changes could be made to CI3 routes too, at least to turn the magic routing off.