Erro em views Slim 3.8


#1

OLA TUDO BEM ESSA ESTRUTURA DE DADOS É A MESMA DO PROJETO 3.0 QUE FOI FEITO COM SLIM
NESSE PROJETO USANDO A VERSÃO 3.8 DA ERRO NO MIDDLEWARE

Slim Application Error
The application could not run because of the following error:

Details

Type: RuntimeException
Message: Callable App\Middleware\Admin\AuthMiddleware does not exist
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\CallableResolver.php
Line: 90
Trace

#0 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\CallableResolver.php(67): Slim\CallableResolver->resolveCallable(‘App\Middleware…’)
#1 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\CallableResolverAwareTrait.php(45): Slim\CallableResolver->resolve(‘App\Middleware…’)
#2 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\DeferredCallable.php(36): Slim\DeferredCallable->resolveCallable(‘App\Middleware…’)
#3 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\Route))
#4 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\Route))
#5 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(122): Slim\Route->Slim{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(122): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#10 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\vendor\slim\slim\Slim\App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#11 C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\SIGA\public\index.php(71): Slim\App->run()
#12 {main}


#2

You should create the middleware “AuthMiddleware”.
Slim simply can’t find it.

Did you run composer dump-auoload?


#3

Please next time write on English.
I understand 'cause i am Italian and the languages are pretty similar :smiley:


#4

I created the Middleware to authenticate user it is in the App / Middleware / AuthMiddleware.php folder

Only Slim is not executing him.
And I do not know where to make change to work anymore.
Because this structure is the same used in other projects
I did using Slim
I’m a beginner
I just made one site with Slim and I’m creating another
With this new version of Slim


#5

The namespace you used in slim is App\Middleware\Admin\AuthMiddleware while the path is App/Middleware /AuthMiddleware.php

You must change the namespace for make it works :smiley:


#6

Sorry, I passed the wrong example.
Namespace
This is correct file.

I think this has got with psr-4

<? Php Namespace App \ Middleware \ Admin; AuthMiddleware class { Public function __invoke ($ request, $ response, $ next) { If (! Isset ($ _ SESSION [PREFIX.logged '])) { Return $ response-> withRedirect (PATH. '/ Admin / login'); } $ Response = $ next ($ request, $ response); // $ response-> getBody () -> write ('AFTER'); Return $ response; } }

#7

are you sure this is the correct code that you are using? because in PHP the class keyword should be before the name of the class not after it. so it should be

class AuthMiddleware

#8

also this should be

namespace App\Middleware\Admin;

with no spaces more info can be found at PHP namespace


#9

class

<?php namespace App\Middleware\Admin; class AuthMiddleware{ public function __invoke($request, $response, $next) { if(!isset($_SESSION[PREFIX.'logado'])){ return $response->withRedirect(PATH . '/admin/login'); } $response = $next($request, $response); //$response->getBody()->write('DEPOIS'); return $response; } }

#10

Yes, in the version, 3.0 this same file works perfectly…


#11

I think this topic is the same as here Urgent slim 3.8 does not recognize my classes and neither my Actions and middleware .

please dont post two topics for the same issue