Uncaught Error: Class not found - Slim Framework

Asked

Viewed 793 times

0

I’m getting this mistake:

Fatal error: Uncaught Error: Class 'CrudUser' not found in /home/doupenglish/www/api/index.php:27 Stack trace: #0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #1 /home/doupenglish/www/api/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #2 /home/doupenglish/www/api/vendor/slim/slim/Slim/Route.php(325): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #3 /home/doupenglish/www/api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(114): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response)) #4 /home/doupenglish/www/api/vendor/slim/slim/Slim/Route.php(297): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response)) #5 /home/doupenglish/www/api/vendor/slim/slim/Slim/App.php(433): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Ht in /home/doupenglish/www/api/index.php on line 27

When I try to make a get using slimframework like this:

$app->get('/usuario',function(Request $request,Response $response){
    $usermail = $request->getHeader('PHP_AUTH_USER');
    $senha = $request->getHeader('PHP_AUTH_PW'); 

    $sql = new Sql();    
    $user = new CrudUser();
    $autenticado = $user->login($usermail,$senha);
    if ($autenticado) {
        $resultado = $sql->select("SELECT * FROM tb_alunos WHERE email = :EMAIL",array(
            ":EMAIL"=>$usermail
        ));
        $response = json_encode($resultados);
    }else{
        $response->withStatus(401);
    }
    return $response;
});

I’m doing auto load with these 2 files, was working

    require 'vendor/autoload.php';
require 'config.php';

config.php file :

    <?php
spl_autoload_register(function($class_name){
    $filename = "class".DIRECTORY_SEPARATOR.$class_name.".php";
    if(file_exists(($filename))){
        require_once($filename);
    }
});
?>
  • let’s go, if the error started after Oce create the class I believe is just run the Composer to "get to know" his new class composer dump-autoload

  • It is already running on the web, however I did that it did not work, it did not start after creating class, I do not know when it started because I left api a few days stopped, and now that I came back stir is not finding the class

  • Create your own spl_autoload_register, since this already using Poser-autoload is to reinvent the wheel, just edit Composer.json and add the folder path class.

  • @Guilhermenascimentop. I’m new in development with Composer and php, as I do auto load with Composer

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.