更改 DOCUMENT_ROOT 或更好的方法
有没有更好的方法来为我的本地环境设置路径。这就是我想要做的,
<?php
if ($_SERVER['SERVER_NAME'] == 'localhost') {
define("URL", "/mysite");
}else{
define("URL", "");
}
?>
这种方法的唯一问题是我需要在我的代码中乱扔这样的东西
<link rel="stylesheet" href="<?php echo URL; ?>/css/main-style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL; ?>/css/home.css" type="text/css" />
<script src="<?php echo URL; ?>/js/jquery.js?v=1.5.2" type="text/javascript"></script>
<?php include($_SERVER['DOCUMENT_ROOT'] . URL . '/inc/header-inc.php'); ?>
,而且我必须找到我网站中的每个绝对路径,并在前面添加 URL,这会使代码变得混乱。我在 MAC osx 上,我的 DOCUMENT_ROOT 是 /Users/alex/Sites
我可以将其更改为 /Users/alex/Sites/mysite 但是当我需要 mysite2 时会发生什么
Is there a better way to take set the path for my local environment. Here is what i am trying to do
<?php
if ($_SERVER['SERVER_NAME'] == 'localhost') {
define("URL", "/mysite");
}else{
define("URL", "");
}
?>
the only problem with this approach is I need to litter my code with stuff like this
<link rel="stylesheet" href="<?php echo URL; ?>/css/main-style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL; ?>/css/home.css" type="text/css" />
<script src="<?php echo URL; ?>/js/jquery.js?v=1.5.2" type="text/javascript"></script>
<?php include($_SERVER['DOCUMENT_ROOT'] . URL . '/inc/header-inc.php'); ?>
And i have to find every absolute path in my site and add the URL in front which is cluttering the code with this. I am on MAc osx and my DOCUMENT_ROOT is /Users/alex/Sites
I can change it to /Users/alex/Sites/mysite but what happens when I need mysite2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个方法
Try this approach