Hi.
The problem is that I use the method file _ get _ contents("body.html")
in a class that is in the same folder as body.html
. The problem is that I get an error saying that the file could not be found. This is because I from another class require the file that uses the method file _ get _ contents("body.html")
, and suddenly I have to use "../body/body.html" as filepath..!
Isn't that a bit strange? The class that calls the method file _ get _ contents("body.html")
is in the same folder as body.html
, but because the class is required from another class somewhere else, I need a new filepath?!
Here's a short list over directories and files:
lib/main/main.php
lib/body/body.php
lib/body/body.html
This is body.php:
class Body {
public function getOutput(){
return file_get_contents("body.html");
}
}
This is 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();
The thing I ask for is a fix on the error that body.php
is in the same folder as body.html
but I have to change the path when a another class requires body.php
from somewhere else in the method file _ get _ contents("body.html")
Thanks!