I am including two files in my index page:
$PageData = new Page_Data();
$PageData->title ="Welcome to my page";
$div= "<div class='login-form'>" . include_once "views/navigation.php" . include_once "controllers/login.php" . "</div>";
$PageData->content .=$div;
And I get these two errors.
Warning: include_once(controllers/login.php): failed to open stream: No such file or directory in C:\Users\kalle_000\Documents\KEA\3rd Semester\3rd Module\Module_8\PHP_new\index.php on line 9
Warning: include_once(): Failed opening 'controllers/login.php' for inclusion (include_path='.;C:\php\pear') in C:\Users\kalle_000\Documents\KEA\3rd Semester\3rd Module\Module_8\PHP_new\index.php on line 9 test content
What am I doing wrong? All the files are in the right folder where they should be. Any help appreciated!
I changed the syntax to this:
$PageData = new Page_Data();
$PageData->title ="Welcome to my page";
$div= "<div class='login-form'>";
$div.= include_once ("views/navigation.php");
$div.= include_once ("controllers/login.php");
$div.= "</div>";
$PageData->content .=$div;
For some reason, the browser didn't understand the previous syntax, but gets this and now it works perfectly. Thanks for the help.
include_once "views/navigation.php" . include_once "controllers/login.php" . "</div>"
This is basically evaluated as
include_once ("views/navigation.php" . (include_once ("controllers/login.php" . "</div>")))
That means first "controllers/login.php" . "</div>"
is tried to be included, then views/navigation.php0
("views/navigation.php"
+ result of the first include
). That obviously won't work very well.
Further, the included content probably won't be concatenated into $div
either, but output directly.
You probably want:
ob_start();
echo "<div class='login-form'>";
include_once "views/navigation.php";
include_once "controllers/login.php";
echo "</div>";
$div = ob_get_clean();