Uncaught Error

Par merciful, il y a 5 ans


Bonjour les amis,

Ce que je fais

Décrivez ici votre code ou ce que vous cherchez à faire

<?php require '../vendor/autoload.php'; $router = new AltoRouter(); define('VIEW_PATH', dirname(__DIR__).'/views'); $router->map('GET', '/blog',function(){ require VIEW_PATH . '/post/index.php'; }); $router->map('GET', '/blog/category', function(){ require VIEW_PATH . '/category/shows.php'; }); $match = $router->match(); $match['target']();

Ce que je veux

Décrivez ici ce que vous cherchez à obtenir

Ce que j'obtiens

Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\TPblog\public\index.php on line 15

Fatal error: Uncaught Error: Function name must be a string in C:\xampp\htdocs\TPblog\public\index.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TPblog\public\index.php on line 15

2 réponses

Balsakup, il y a 5 ans

Salut,

$match est un booléen, var_dump($match) pour le voir, donc tu ne peux pas y accéder comme un tableau. D'après la doc : If a match was found, the match() method will return an associative array with the following 3 keys..

Donc tu devrais faire

if( is_array($match) && is_callable( $match['target'] ) ) { call_user_func_array( $match['target'], $match['params'] ); } else { // no route was matched header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); }
merciful, il y a 5 ans

Merci beaucoup Balsakup.