Class php is not find

Related searches

I finished my website in localhost with MAMP and everything works fine.

But now I update it to my web site and I have this issue:

Fatal error: Uncaught Error: Class 'App\Model\FrontChapter' not found in /home/rafaueuu/public_html/pro4/App/Controller/FrontController.php:9 Stack trace:

0 [internal function]: App\Controller\FrontController->home()

1 /home/rafaueuu/public_html/pro4/App/Router/Route.php(38): call_user_func_array(Array, Array)

2 /home/rafaueuu/public_html/pro4/App/Router/Router.php(27): App\Router\Route->callAction()

3 /home/rafaueuu/public_html/pro4/index.php(51): App\Router\Router->match()

4 {main}thrown in /home/rafaueuu/public_html/pro4/App/Controller/FrontController.php on line 9

If I understud my controller don't find the Class but wy is working in localhost?

share you some code:

public function home(){
    $conn = new FrontChapter(); //LINE 9
    $lastChapter = $conn->lastChapter();
    require './view/frontend/home.php';

public function callAction(){
        $elements = explode('@', $this->action);
        $class =  $elements[0];
        $method = $elements[1];
        $controller = "App\\Controller\\" . $class;
        $controller = new $controller;
        return call_user_func_array([$controller, $method], $this->matches);//LINE 38
    } else{
        return call_user_func_array($this->action, $this->matches);

public function match(){
    foreach($this->routes[$_SERVER['REQUEST_METHOD']] as $route){
            return $route->callAction();//LINE 27

just ad my index in case:

require 'vendor/autoload.php';
echo '<pre>';
ini_set('display_errors', 1);
echo '<pre>';

$router = new App\Router\Router($_GET['url']);
$router->get('/', 'FrontController@home');
$router->get('/auteur', 'FrontController@author');
$router->get('/chapitre', 'FrontController@indexChapter');
$router->get('/contact', 'FrontController@contact');
numero/:id','FrontController@displayChapter')->with('id', '[0-9]+');
$router->post('/chapitre-numero/:id_article' , 
'FrontController@comments')->with('id_article', '[0-9]+');
$router->get('/signaler/:id' , 'FrontController@reportComment')- 
>with('id', '[0-9]+');
$router->get('/404' , 'FrontController@erreur404');
$router->get('/404-article' , 'FrontController@article404');

//gestion chapitres
$router->get('/chapitres-admin', 'BackController@displayChapter');
'BackController@updateChapter')->with('id', '[0-9]+');
'BackController@updateChapter')->with('id', '[0-9]+');
'BackController@deleteChapter')->with('id', '[0-9]+');
//nouveau chapitres
$router->get('/nouveau-chapitre', 'BackController@createChapter');
$router->post('/nouveau-chapitre', 'BackController@createChapter');
//gestion commentaires
$router->get('/valider-com/:id', 'BackController@validateComment')- 
>with('id', '[0-9]+');
$router->get('/supprimer-com/:id', 'BackController@deleteComments')- 
>with('id', '[0-9]+');
//gestion des administrateurs
$router->get('/nouveau-admin', 'BackController@createAdmin');
$router->post('/nouveau-admin', 'BackController@createAdmin');
$router->get('/modifier-admin/:id' , 'BackController@updateAdmin')- 
>with('id', '[0-9]+');
$router->post('/modifier-admin/:id' , 'BackController@updateAdmin')- 
>with('id', '[0-9]+');
$router->get('/effacer-admin/:id' , 'BackController@deleteAdmin')- 
>with('id', '[0-9]+');
$router->get('/gestion-admin' , 'BackController@displayAdmin');
$router->get('/message-admin' , 'BackController@displayMessage');
$router->post('/contact' , 'BackController@postMessage');
$router->get('/effacer-message/:id' , 
'BackController@deleteMessage')->with('id', '[0-9]+');
$router->get('/connexion', 'BackController@login');
$router->post('/connexion', 'BackController@login');
$router->get('/deconnexion' , 'BackController@logout');
$router->get('/admin', 'BackController@indexAdmin');


the composer.json

"require": {},
"autoload": {
    "psr-4": {
        "App\\" : "App",
        "Model\\" : "Model"

I hope some one understand me i just started php, thx for your help

EDIT: i use only namespaces not include function maybe is something about composer auto load?

Here are two things to try in case you haven't already:

  1. Run composer install on the server.

  2. Change this require 'vendor/autoload.php'; to this require '/vendor/autoload.php';

php - How to fix "Class '' not found" error, So there are a few things you can do to fix the "Class '' not found" in PHP. Typically it's just a typo or a uppercase where it should be lower or vice versa, in the namespace. Fatal error: Class 'MySQL' not found in C:\xampp\htdocs\\php\core.php on line 44 So looks like the class is just not being declared!! For some damn reason!

when you use the namespace or use it, the class path doesn't start with the slash '\'. but when you have to recall a class and use it directly, you have two possibilities:

use App\Model\MyClass

$obj = new MyClass;


$obj = new \App\Model\MyClass;

because depending on the use you make of it, the paths are different. happy Holidays

class_exists - Manual, Be careful and don't forget about second boolean argument $autoload (TRUE by default) when check exists class after spl_autoload_register. Propose short� I'm running PHP 5.3.4 on Windows 7 and had some difficulty autoloading classes using class_exists(). In my case, when I checked for the class and it didn't exist, class_exists automatically threw a system Exception.

My answer is very simple and if you are a noob like me and have the same problem dont forget to do a composer dump-autoload -o in your console to generate the autoload files for news namespaces.

FAQ: things you need to know about namespaces - Manual, Class names that do not contain a backslash like name can be resolved in 2 or fully qualified, that contains a backslash will produce a fatal error if not found. Hello, I'm using Mac as my development environment for my website and my project hierarchy is as follows: --root/ --frameworks/ --myFramework.php --PHPMailer.php This is my simple function to send

Autoloading Classes - Manual, Want to load NonLoadableClass. Want to load MissingException. Fatal error: Class 'MissingException' not found in testMissingException.php on line 4� Class schedules and class sections are updated regularly. Please check back if you do not find the class that you need. Click "More Search Options" in the lower left corner to filter your search. Register for classes in the Maricopa Student Center at

get_class - Manual, I made such a method for one of my classes in PHP5, but found out that static methods in PHP5 do not 'know' the name of the calling subclass', so I use a� require_once all the files each class needs in each class file; write an __autoload() function so that PHP can find all your classes whenever it thinks it needs one; The 2nd option is more flexible. If you want to know classes are available from a particular place try outputting get_declared_classes()

Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

  • So, do you have class FrontChapter in App\Model namespace?
  • @freeek yes in the namespace App\Model
  • We need to check composer.json autoload section and this class structure then. Where do you keep it, can you create this class it from any other file?
  • @freeek Just edit the question now
  • Check folder name, and also, this could be crazy - try add slash after: Model/.
  • I try the second option and i have a new problem vendor is not find. And for the first i nedd to install composer on my web server ?
  • happy holidays to you to. I think i understand that, my problem here is that my code works fine in my local server but have this problem on the web server?