【发布时间】:2016-04-12 23:00:29
【问题描述】:
我在包含一个包含包含一些 js 脚本库的文件的文件时遇到问题。
index.php
<?php
include 'header.php';
?>
<section>
<div>
<p>misc. html</p>
</div>
</section>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
页脚.php
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/includes/footerscripts.php');
?>
</body>
</html>
/includes/footerscripts.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php
$testVar = 'test';
?>
在那种情况下,索引文件在运行时在源代码中确实有这个:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
test =
脚本正在运行,但没有被执行,变量也没有通过。
当我将 footer.php 更改为直接包含这些脚本和变量时,该变量会将其变为 index.php,脚本也是如此,但它们没有执行(或没有按时执行?)。
各位有什么想法吗?
我有一个奇怪的 php5.ini 文件,因为我不知道要在里面放什么,如果有什么不同的话。包含文件路径似乎没问题,因为它在大多数情况下仍然有效。
谢谢, 马特
编辑:添加了包含('header.php'),它工作正常并拉入我的标题。
那个文件看起来像:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="--">
<meta name="keywords" content="--">
<meta name="author" content="--">
<title>--</title>
<link rel="stylesheet" href="/css/mainstylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="icon" href="/images/favicon.ico">
</head>
<body>
<header class="nav-top" id="top" role="navigation">
<div class="container">
<div class="home-link">
<a href="../"><img src="/images/logo/logo-p.png" alt="plc" class="logo" /></a>
</div>
<nav class="nav-main">
<ul>
<li>
<a href="../">Home</a>
</li>
<li>
<a href="/portfolio">Portfolio</a>
</li>
<li>
<a href="/contact">Contact</a>
</li>
</ul>
</nav>
</div>
</header>
编辑:我想我只需要从文档的标题加载我的 jquery,因为它是这样工作的。我仍然不能将变量从孙子传递给父母,但是哦,好吧
【问题讨论】:
-
将你的
include更改为require并观察失败的地方。 -
我做到了,它没有失败,jqery 和 bootstrap.js 文件只是不执行
-
$_SERVER['ROOT']你的意思是:$_SERVER['DOCUMENT_ROOT']