CakePHP Overriding DS
I am trying to override DS to use '/' instead of '\' in my Windows Dev machine. The reason for this is on certain jav开发者_开发技巧ascript, it's using cake's DS for some ajax call.
For instance:
var data = '<?php echo 'image' . DS ?>';
This is a problem as javascript takes \ as an escape character, so the js becomes
var data = 'image\';
Any light on this is appreciated, thank's!
EDIT: I probably should let out more info on this =/
I am trying to develop an application locally on my Windows machine. Now, the web app is assuming that the developer is running on linux, so the previous developers are using php DS all over the place. Of course I could just change those DS into / which probably won't harm anyone. But for an application with thousand files, it's probably better not to do it that way, so I was thinking of overriding DS for my own local working copy. The example above is just a tiny snippet to show what I'm trying to achieve, not the actual code used.
But nevermind, I'll be just using ZWAMP and be on my way. Thank's for the responses :D
You should not do that. DS is the Directory Separator that must be left as-is, well, the directory separator. Which is '/' on Unix, and '\' on MS machines.
In AJAX calls, always use '/'. You do not need any variable for this: the separator in URLs is always '/' you can just type it into the string literal. (Even if your URL starts with file:///...)
What JS is using PHP's DS? This does not make sense to me.
Actually you can safely define DS to '/'. Windows will still recognize it. For example windows will treat c:/windows/system
same as c:\windows\system
. Even windows will recognize if you write c:\windows/system
.
So, replace DS definition in your app/webroot/index.php from:
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
to
if (!defined('DS')) {
define('DS', '/');
}
It might be worth trying \\
the DS short form of the DIRECTORY_SEPARATOR which is a predefined constant in the PHP. That means the PHP environmet set it up for you, so if you are in windows then it will be '\' if your code is running on *nix environment then it will be a '/'.
Also worth to have a look on the following forum conversation as well:
http://www.talkphp.com/general/2487-directory_separator-not-necessary.html
精彩评论