Вопрос

Trying to improve a custom codeigniter route regex that I have created. Essentially the purpose of the custom route is to create a cleaner/shorter URL for client profile pages which have the format of clients/client-slug, for example: clients/acme-inc. I only want this route to match if their are no additional segments after the client-slug segment, and if they client-slug value does not match any of the 'reserved' values which correspond to actual methods/routes in the Clients controller. Currently, this is what I'm using:

$route['clients/(?!some_method|another_method|foo|bar)(.+)'] = 'clients/index/$1';

This mostly works ok, except for when there is a client-slug that begins with one of the reserved methods text, i.e. clients/food-co, which since it has clients/foo in it, the custom route is not matched. So I need to basically conditionally allow the route to contain any of the reserved methods in that set ONLY IF it is followed by additional characters (that is not a /).

Это было полезно?

Решение

Do you try this?

$route['clients/(?!(?:some_method|another_method|foo|bar)(?:/|$))(.+)'] = 'clients/index/$1';

Другие советы

You should consider the _remap() method in the future. It will allow you to update your controller and add new methods without needing to update your route (you actually wouldn't need a route at all, so long as your URI matches the controller name).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top