-2

I am using Cake, but how do I make the routing like:

Router::connect('/', array('controller' => 'homes', 'action' => 'index'));

case insensitve?

For instance:

Router::connect
(
    '/:user', 
    array('controller' => 'teachers', 'action' => 'contentProfile', 1),
    array('user' => 'hellouser')
);

MY_URL.com/hellouser works fine but not MY_URL.com/HelloUser does NOT route correctly.

And I have tried /heelouser/i and still nothing.

cdub
  • 24,555
  • 57
  • 174
  • 303
  • to be like twitter: http://twitter.com/EV and http://twitter.com/ev and why does it matter what I need it for? – cdub Sep 21 '12 at 07:39
  • either you have to use .htaccess to rewrite your urls to upper to lower and vice versa or make your apache case insensitive – GBD Sep 21 '12 at 07:41
  • 4
    '/' is already case insensitive – AD7six Sep 21 '12 at 07:42
  • no there is a cakephp why to do it with preg_match – cdub Sep 21 '12 at 07:44
  • 1
    Like AD7six said "/" is already case insensitive – ADmad Sep 21 '12 at 07:54
  • Give a real example, and you then at least stand a chance of getting a real answer – AD7six Sep 21 '12 at 07:54
  • 3
    would you mind clarifying the upper and lower case forms of '/' ? – AD7six Sep 21 '12 at 07:58
  • @AD7six do you know anything about cake routing or cakephp? – cdub Sep 21 '12 at 07:59
  • 5
    no chris, @ADmad and I are complete noobs. https://github.com/cakephp?tab=members – AD7six Sep 21 '12 at 07:59
  • btw "why does it matter.." isn't a very nice tone when asking for help on a public forum. – ADmad Sep 21 '12 at 08:00
  • so why is my route not working, no one has an answer... – cdub Sep 21 '12 at 08:00
  • me too, just following what the cakebook says http://book.cakephp.org/2.0/en/development/routing.html – cdub Sep 21 '12 at 08:02
  • 1
    in what way is it not working.. I don't have the patience to pull info out of you I'm afraid. – AD7six Sep 21 '12 at 08:03
  • its in my edit, i use the above route, and type myurl.com/hellouser and it routes, but myurl.com/HelloUser does not and looks for HelloUser controller – cdub Sep 21 '12 at 08:05
  • 1
    "and looks for HelloUser controller" is not in your edit. "does NOT route correctly (no further clarification)" is in your edit - good luck. – AD7six Sep 21 '12 at 08:07
  • can you not understand my edit, looks pretty clear to me what I'm asking? – cdub Sep 21 '12 at 08:09
  • Why do you want to match a specific user in the route? Just pass the name through to a controller where you do with it whatever you want. You're not going to make a new route per user anyway, right? – deceze Sep 21 '12 at 08:13
  • i am not going to make a new route, just for certain special users right now, so i just need this answer, should be simple – cdub Sep 21 '12 at 08:16

1 Answers1

4

As indicated in the docs, you can use regular expressions to restrict matching route elements. The regex snippet you are looking for is:

'(?i:hellouser)' 

Route definition

Putting the docs and your specific regex together, here's a route that will match the url /hellouser in a case insensitive manner:

Router::connect(
    '/:user', 
    array('controller' => 'teachers', 'action' => 'contentProfile', 1),
    array('user' => '(?i:hellouser)')
);

The third argument is used to restrict the possible values of route elements - in this case to "hellouser" in a case insensitive manner.

AD7six
  • 63,116
  • 12
  • 91
  • 123
ADmad
  • 8,102
  • 16
  • 18
  • it would have worked in cake 1.2 but in 2 they took it out – cdub Sep 21 '12 at 08:23
  • see this: http://stackoverflow.com/questions/11690966/easy-way-to-add-case-insensitive-routing-in-cakephp-2 – cdub Sep 21 '12 at 08:23
  • @chris you still don't seem to get that @ADmad is part of the core team (and me). That means you can be quite sure information provided is not fundamentally flawed. What that means here is you're reading it wrong - `array('user' => put regex here)` is what you should be doing. there are examples of this [in the book](http://book.cakephp.org/2.0/en/development/routing.html#route-elements) – AD7six Sep 21 '12 at 08:26
  • obviously I know you are part of the core team, but the answer above isn't working – cdub Sep 21 '12 at 08:28
  • i'm not the only one online with that problem, as you can see by the stack overflow link in my comments, but my answer works correctly – cdub Sep 21 '12 at 08:29
  • Yay +1 ADmad. You can tell his answer was going to be good because he doesn't have a set of numbers at the end of his nickname. – Jose Diaz-Gonzalez Sep 21 '12 at 08:39
  • what's with the numbers at the end of the nickname comment mean? – cdub Sep 21 '12 at 08:45