user873684
user873684

Reputation: 69

Fatal error uncaught error class not found

I'm currently getting this error while migrating to a online provider

Fatal error: Uncaught Error: Class 'app\Http\model\MoviePresenter' not found in /home/index.php:4 Stack trace: #0 {main} thrown in /home/index.php on line 4

This code works locally fine it's just decided to stop working on the host.

below is some of the code

<?php ini_set('display_errors', 1);

$moviePresenter = new \app\Http\model\MoviePresenter; $movieGenreList = $moviePresenter->getMovieGenreList();

function displayMovieList($movieList, $moviePresenter)
{
      $html = '<div class="movie-list row">';   
      $currentURL = \Request::root();  
      foreach ($movieList as $movie) {
          $genreList = $movie->getGenres();
          $movieGenreList = $moviePresenter->getMovieGenreList();

          foreach ($genreList as $genre){
             foreach ($movieGenreList['genres'] as $movieGenre){
                 if($genre->getID() == $movieGenre['id']){
                 $genre->setName($movieGenre['name']);
             }
          }
      }

     $movieID = $movie->getID();   
     $image = $movie->getPosterImage();  
     $poster = '<img class="img-responsive" src="//image.tmdb.org/t/p/w154/'. $image .'" width="195" height="360">';


     $html .= '<div class="col-xl-3 col-lg-4 col-md-6 col-sm-12 d-flex align-items-center flex-column justify-content-center h-100"><a
     href="' . $currentURL . '/movie/' . $movieID . '">';

    $html .= $poster;
    $html .= '</a><div class="moviedetails row">';

    foreach($genreList as $genre){
      $html .= '<a href="'. $currentURL . '/discovery/genre/'. $genre->getID() . '" class="genres">';
      $html .= $genre->getName() . '</a>';
    }

    $html .= '</div></div>';   
    $html .= '</div>';

    return $html; 
}
?>

It looks like it's looking within the view (where the snipit is from) for the class instead of the file path.

Can anyone tell me why it's searching the local class instead of the view?

Upvotes: 0

Views: 6243

Answers (3)

user10104489
user10104489

Reputation: 11

The error Class 'app\Http\model\MoviePresenter' not found, when you use new class MoviePresenter, but you haven't imported the Class MoviePresenter.

So you should import the class MoviePresenter in the file index.php, try using require() at the beginning in your file like this:

require('app\Http\model\MoviePresenter');
//PUT YOUR OTHER CODE BELOW THIS

Upvotes: 0

Piash
Piash

Reputation: 1131

I don't know which Laravel version you are using. You should give more details regarding your question.

Try importing the MoviePresenter model at the beginning in your file like this

use App\MoviePresenter;

or according to your model file directory like this

use App\Http\model\MoviePresenter;

Upvotes: 0

Elisio L Leonardo
Elisio L Leonardo

Reputation: 249

It may be because of case sensitivity issues. I bet your new host is Linux, so your namespace should be:

\App\Http\model\MoviePresenter

or \App\Http\Model\MoviePresenter

instead of app\Http\model\MoviePresenter

The laravel App namespace use Uppercase A.

Upvotes: 1

Related Questions