我有以下目录结构:
/webroot
/static
/img
/css
- style.css
/js
/pdf
/mp3
/mp4
- index.php在我的'index.php'中,我有以下代码:
// define the frontend path constant
$frontend = realpath(dirname(__FILE__));
define('__FRONTEND__', $frontend);我有我的模板在后端(在webroot之外),当我像这样编写代码时:
<link type="text/css"
rel="stylesheet"
href="<?php echo __FRONTEND__; ?>/static/css/style.css"
/>未显示CSS代码。我也没有收到任何警告。当我查看源代码时,我看到:
<link type="text/css"
rel="stylesheet"
href="C:\xampp\htdocs\projectx\webroot/static/css/style.css"
/>在这里你可以看到不同的斜杠:'\'和'/'。奇怪的是,在我的'index.php'中也有后端常量'__BACKEND__'时,使用相同类型的结构不会失败
// define the frontend path constant
$backend = realpath(dirname(__FILE__) . '/../backend');
define('__BACKEND__', $backend);为什么我的'__FRONTEND__'常量失败了?
发布于 2012-05-17 21:51:57
你不应该在你的模板中使用realpath(dirname(__FILE__))。这是系统的路径,而不是您的用户可以访问的路径。
如果您的web根目录如您所说的是webroot/,那么href="/static/css/style.css"就可以完成此任务。
此外,您的问题与斜杠和反斜杠无关,两者都可以在Windows中工作。
https://stackoverflow.com/questions/10636903
复制相似问题