Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hassanshahzadaheer's avatar

Warning: require(views/{$name}.view.php):

Hi! I am facing this problem from last night I try a lot but not fix can anyone guide me how to fix this?

I make changes in pages controller file

<?php
class PagesController
{

  public function home()
  {
    $tasks = App::get('database')->selectAll('tasks');

    return view('index');

  }

  public function about()
  {

    return view('about');

  }

  public function contact()
  {
  return view('contact');

  }
}
 ?>

and got this error

Warning: require(views/{$name}.view.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/re-test/index.php on line 8

Fatal error: require(): Failed opening required 'views/{$name}.view.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/re-test/index.php on line 8

but I have a view function inside bootstrap.php let me show you this file

<?php


App::bind('config', require 'config.php');


App::bind('database', new QueryBuilder(
    Connection::make(App::get('config')['database'])
));

  function view($name)
  {
    return 'views/{$name}.view.php';
  }

?>

when I remove the

require from index.php 

require Router::load('routes.php')
  ->direct(Request::uri(), Request::method());


to 

Router::load('routes.php')
  ->direct(Request::uri(), Request::method());

then nothing gets display just white screen to appear on refresh

you can check the complete code on https://github.com/hassanshahzadaheer/Refactoring-to-Controller-Classes-ep-23

0 likes
1 reply
Snapey's avatar
Snapey
Best Answer
Level 122

You need to put your string in double quotes so that the string can be interpolated and the view name inserted

 return "views/{$name}.view.php";

There may be other issues, but this is definitely wrong, and matches your error message

1 like

Please or to participate in this conversation.