hassanshahzadaheer
4 months ago

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

Posted 4 months ago by hassanshahzadaheer

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

Please sign in or create an account to participate in this conversation.