我正在尝试在 php 中实现一个简单的前端 Controller 。 在我的 index.php 中;
$parts = array_slice(explode('/',$_SERVER["REQUEST_URI"]),3);
if(file_exists($parts[0].'.php'))
include $parts[0].'.php';
else
echo 'not found';
所以我输入地址栏 localhost/myroot/index.php/home,我希望包括 home.php。 它包括 home.php 但没有外部 css 文件和 javascript 源..它们都没有加载..
在 home.php 中,
<link rel="stylesheet" type="text/css" href="styles/master.css" />
<script type="text/javascript" src="scripts/master.js"></script>
根目录下有styles和scripts目录 /myroot/styles/master.css /myroot/scripts/master.js
所以如果我输入 localhost/myroot/home.php,它会正常工作。
最佳答案
停止为您的 CSS 和 JS 使用相对 URL
关于javascript - 简单的前端 Controller 导致 php 中的 css 和 javascript 损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7680172/