问题是我file _ get _ contents("body.html")
在与body.html
. 问题是我收到一条错误消息,提示找不到该文件。这是因为我来自另一个班级需要使用该方法的文件,file _ get _ contents("body.html")
突然我不得不使用“../body/body.html”作为文件路径..!
这不是有点奇怪吗?调用该方法的类与file _ get _ contents("body.html")
位于同一个文件夹中body.html
,但是由于其他地方的另一个类需要该类,所以我需要一个新的文件路径?!
这是目录和文件的简短列表:
lib/main/main.php
lib/body/body.php
lib/body/body.html
这是body.php:
class Body {
public function getOutput(){
return file_get_contents("body.html");
}
}
这是 main.php:
require '../body/body.php';
class Main {
private $title;
private $body;
function __construct() {
$this->body = new Body();
}
public function setTitle($title) {
$this->title = $title;
}
public function getOutput(){
//prints html with the body and other stuff..
}
}
$class = new Main();
$class->setTitle("Tittel");
echo $class->getOutput();
我要求的是修复与body.php
在同一文件夹中的错误,但是当另一个类从方法中的其他位置body.html
需要时,我必须更改路径body.php
file _ get _ contents("body.html")
谢谢!