问题是我在与body.html
位于同一文件夹中的类中使用方法file _ get _ contents("body.html")
。问题是我得到一个错误,说该文件找不到。这是因为我从另一个班级需要使用方法file _ get _ contents("body.html")
的文件,并且突然间我必须使用“../body/body.html”作为文件路径。php中的filepath如何工作?
这是不是有点奇怪?调用方法file _ get _ contents("body.html")
的类与body.html
位于同一文件夹中,但由于该类是其他位置的其他类所必需的,因此我需要一个新的文件路径?!
这里结束了目录和文件的简短列表:
的lib /主/ main.php
的lib /体/ body.php
的lib /体/ body.html
这是身体.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")
由于改变路径!
这也帮助了我,谢谢! – ItsMeDom 2014-03-31 03:04:11