-1

这就是我所拥有的。我的 /root/ 文件夹中有一个 index php 页面,其中包含以下代码:

index.php

require_once("access/$template/head.php");

我的功能页面对 $template 代码有以下配置:

funcs.php

function getTemplateFiles() { 
    $directory = "models/site-templates/"; 
    $languages = glob($directory . "*");  
    return $languages; 
}

我的头 php 页面有以下代码:

头文件

<link rel='stylesheet' href='$template/css/style.css'>

我的问题是我可以添加什么代码到我的索引页面来与我的头页面通信,我的 $template 之前的代码将包含我的 php 页面的文件位置。

示例 1

$include_dir/$template/css/style.css'>

我的问题是如何包含我的索引页面的路径,以便我的头页面将像这样读取为 html?

默认,不起作用$template/css/style.css

仅索引页面需要这样access/$template/css/style.css

4

2 回答 2

0

替换你的代码

<link rel='stylesheet' href='$template/css/style.css'>

用这个

<link rel='stylesheet' href='<?php echo $template; ?>/css/style.css'>
于 2013-07-06T04:53:42.397 回答
0

我不太确定我是否正确理解了您的问题,但这两种方法可能会有所帮助:

$currentDir = dirname(__FILE__);

$currentDir将是您服务器上当前所在文件的路径。因此,如果您有这样的结构:

/access/functions/myFunction.php

并且您从 myFunction.php 调用此方法,$currentDir将返回“/access/functions”。如果要包含的文件位于同一目录路径中,则可以像这样包含它:

$includePath = $currentDir."/myFile.php";

确定目标目录的另一种方法是使用:

$docRoot = realpath($_SERVER["DOCUMENT_ROOT"]);

$docRoot将是您网站的顶级目录(通常类似于 /usr/www/username/public_html/)

使用这个,你总是知道你的顶级目录是什么,然后你可以包含这样的文件:

$includePath = $docRoot."/models/site-templates/myTemplate.css";
于 2013-07-06T12:15:48.053 回答