Sorry I new to SLIM3 this not sure why I this is happening. So please bear with me
$app->get(’/hello/{name}’, function (Request $request, Response $response) {
$name = $request->getAttribute(‘name’);
$response->getBody()->write(“Hello, $name”);
return $response;
});
$app->get(’/Beer’, function (Request $request, Response $response) {
echo “HELLO BEER”;
});
I am getting this error. Why?
Details
Type: FastRoute\BadRouteException
Message: Static route “/Beer” is shadowed by previously defined variable route “/([^/]+)” for method "GET"
File: /Users/dmcnight/Documents/Repos/beer-framework-v2/beer-frame-work/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php
Line: 64
Have you provided all your registered routes?
Yes. Those are the only 2. I get that when I go to either route.
So there should be registered additional wildcard route. You should show us more code.
This is all the code in the index.php file.
$<?php
if (PHP_SAPI == ‘cli-server’) {
// To help the built-in PHP dev server, check if the request was actually for
// something which should probably be served as a static file
$file = DIR . $_SERVER[‘REQUEST_URI’];
if (is_file($file)) {
return false;
}
}
//register classes
spl_autoload_register(function ($classname) {
require ("…/classes/" . $classname . “.php”);
});
require DIR . ‘/…/vendor/autoload.php’;
session_start();
// Instantiate the app
$settings = require DIR . ‘/…/src/settings.php’;
$app = new \Slim\App($settings);
// Set up dependencies
require DIR . ‘/…/src/dependencies.php’;
// Register middleware
require DIR . ‘/…/src/middleware.php’;
// Register routes
require DIR . ‘/…/src/routes.php’;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->get(’/hello/{name}’, function (Request $request, Response $response) {
$name = $request->getAttribute(‘name’);
$response->getBody()->write(“Hello, $name”);
return $response;
});
$app->get(’/Beer’, function (Request $request, Response $response) {
// $beer = new Beer(“Bells Two Hearted”, “Good IPA”);
// var_dump($beer);
echo “HELLO BEER”;
});
// Run app
$app->run();
llvdl
April 28, 2016, 9:02pm
6
Are there any routes defined in src/routes.php
?