問題是我在與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