Erro na rota | Fórum | School of Net

Deseja poder participar de nosso fórum e tirar todas as suas dúvidas?
Clique aqui e assine nosso plano de acesso ilimitado. Saiba mais.

por João Ricardo

1 semana, 2 dias atrás João Ricardo

Erro na rota

Olá pessoal. Estou com problemas na minha rota, fiz como o instrutor fez mas me retorna esse erro ``` Notice: Trying to get property 'attribute' of non-object in C:\xampp\htdocs\CursoPHPDoctrine\src\routes.php on line 28 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\CursoPHPDoctrine\src\routes.php on line 28 Notice: Trying to get property 'handler' of non-object in C:\xampp\htdocs\CursoPHPDoctrine\src\routes.php on line 33 Fatal error: Uncaught Error: Function name must be a string in C:\xampp\htdocs\CursoPHPDoctrine\src\routes.php:35 Stack trace: #0 C:\xampp\htdocs\CursoPHPDoctrine\public\index.php(3): require_once() #1 {main} thrown in C:\xampp\htdocs\CursoPHPDoctrine\src\routes.php on line 35 ``` Código routes.php ``` <?php use Aura\Router\RouterContainer; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequestFactory; $request = ServerRequestFactory::fromGlobals( $_SERVER,$_GET,$_POST,$_COOKIE,$_FILES ); $routerContainer = new RouterContainer(); $map = $routerContainer->getMap(); $map->get('home',"/",function($request,$response){ $response->getBody()->write("Hello World"); return $response; }); $matcher = $routerContainer->getMatcher(); $route = $matcher->match($request); foreach ($route->attributes as $key => $value) { $request = $request->withAttribute($key,$value); } $callable = $route->handler; $response = $callable($request,new Response()); /** @var Response $response */ echo $response->getBody(); ```

7 Respostas