controller file name case sensitive

In Linux, file names are case sensitive. From what I can tell, it appears that Yii does not handle full case-sensitivity, at least when dealing with controllers. By default the beginning char of the controller name is upper case, and the 'C' in Controller is upper case, but if camel hump notation is used in other parts of the controller name, Yii can't find the controller file. For example:

if the Controller file is named "MycustomController.php" it works just fine. However, if the controller is named "MyCustomController.php", Yii gives an error like: "Page Not Found The requested controller "mycustom" does not exist."

Does what I'm describing sound accurate (in regards to the way that Yii handles a controller w/camel hump notation)? Is there a work-around, or do I have to re-name all of my controller files?

Any input is appreciated. Thanks in advance!

Yes, you need to rename your controller file names.

Is there not a way to preserve case when including files? I always name my class names the same as my class files. So, for example, MyCutomClass.php contains a class definition like:



class MyCustomClass


{


...


}


Therefore, if YiiBase is attempting to include the controller file based on the class name, like include($className.'.php'), shouldn't it still work since my class name DOES use the same case and notation as the file name?

Sorry, I think I'm confused…

You said you have a controller file named "MyCustomController.php". Then the controller ID would be "myCustom", not "mycustom" because file name is case-sensitive on *nix.

Thanks, Qiang! Now I see. The problem is not that Yii can't find my Controller class file. The problem is that the controller and/or action ID that I used (being all lowercase) did not correspond to my actual controller and/or action name (which used camel hump notation). I had assumed that Yii treated the controller on the file system level as being case sensitive, but that the controller ID was always lowercase or case insensitive. Thanks for helping me understand how this works.

You may also take a look at CUrlManager::caseSensitive. This defaults to true, meaning Yii won't do any special processing about these IDs. If you set it to false, Yii will convert controller/action IDs to lower case before dispatching the request to a controller.

Sorry for digging old stuff up.

I have a very little bit problem on this in 1.0.6

Story:

  1. I put the application in c:\wwwroot\YiiTest\

  2. 'urlFormat'=>'path', caseSensitive=>false

Please note the character case of YiiTest

I have a problem when I accessed e.g:http://localhost/yiitest/site/contact, it always back to index page.

But it will be fine when using http://localhost/YiiTest/site/contact

Please note the difference yiitest and YiiTest.

With a bit of trial error, I found that when I remove ‘urlFormat’=>‘path’ everything is ok.

I'm not sure if this is a bug, so I put to the related thread.

Thank you Qiang

If you set caseSensitive=>false, you need to make sure your controller class is named as YiitestController (note only letter Y and C are in upper case).

yes, I confirm that when urlFormat is set to get the action would be case insensitive

eg. all of the following works

localhost/?r=foo/bar

localhost/?r=foo/bAr

localhost/?r=foo/bAR

localhost/?r=foo/BAR

while path won’t

localhost/foo/bar

to fix this, there would be no need to change urlFormat from path to get

I dared to make the following core patch

— yii/framework/web/CWebApplication.php (old copy)

+++ yii/framework/web/CWebApplication.php (working copy)

@@ -115,9 +115,16 @@

$route=$this->catchAllRequest[0];

foreach(array_splice($this->catchAllRequest,1) as $name=>$value)

$_GET[$name]=$value;

  • } else {

  • $route=$this->getUrlManager()->parseUrl($this->getRequest());

  • $a=explode(’&’, $route);

  • $route=$a[0];

  • $_GET[‘r’]=$route;

  • foreach(array_splice($a,1) as $i) {

  • list($j, $k)=explode(’=’, $i, 2);

  • $_GET[$j]=$k;

  • }

}

  • else

  • $route=$this->getUrlManager()->parseUrl($this->getRequest());

$this->runController($route);

}

and it worked,

but in both ‘get’ and ‘path’ the controller is case sensitive

any suggestion other than to rename all classes and folders to be lowercased ?