Question

I have my own MVC and autoloader that loads classes. Everything works except that my base View.php is in Core folder and its render function does the following:

   public function render($file) {
        include('Project/Views/index/header.php');
        include('Project/Views/'.strtolower($file).'.php');
        include('Project/Views/index/footer.php');
   }

View.php uses a namespace

namespace Core;

when i go to my index page it gives:

Warning: include(Projcet/Views/index/header.php): failed to open stream: No such file ...

I tried the following: i added

use Project\Views;

and instead of include i did:

$header = new Views\index\header();

This shows the header on the page but it also gives an error:

'Project\Views\index\header' not found

I know its because header.php is not a class. It's a view file. So I don't know, how to include the file, when autoloader is loading the View.php for base Controller.

Was it helpful?

Solution

The error message (if you copy-pasted it verbatim) looks like you're including files from the wrong folder:

Warning: include(Projcet/Views/index/header.php): failed to open stream: No such file ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top