Coffeecode Router Error 400 on all routes

Asked

Viewed 218 times

0

Good morning, good afternoon or good night.

I am learning to use the Coffeecode Router component but it always returns me the 400 error regardless of the route I access, I did a search and did not find much, I use php 7.4.

This is my Index.php

<?php

require __DIR__ . "/vendor/autoload.php";

use CoffeeCode\Router\Router;

$router = new Router("http://localhost/Teste%20Mongo");

$router->namespace("Source/App");

//$router->group(null);
$router->get("/", "Web:index");

$router->group("ooops");
$router->get("/{errcode}", "Web:error");

$router->dispatch();

if ($router->error()) {
    $router->redirect("/ooops/{$router->error()}");
}

My Controller, It is on the way Source/App/Web.php

<?php

namespace Source\App;

class Web
{

    public function index($data)
    {
        echo 'Index';
    }

    public function error($data)
    {
        echo 'Error';
    }
    
}

My Komposer.json

{
    "require": {
        "mongodb/mongodb": "^1.6",
        "coffeecode/router": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "Source\\App\\": "Source/App"
        }
    }
}

1 answer

0

People found the problem, the error was in the namespace line

$router->namespace("Source/App");

I was just changing the / by I hadn’t realized it.

Follows the corrected index class

require __DIR__ . "/vendor/autoload.php";

use CoffeeCode\Router\Router;

$router = new Router("http://localhost/Teste%20Mongo");

$router->namespace("Source\App");

$router->group(null);
$router->get("/", "Web:index");

$router->group("ooops");
$router->get("/{errcode}", "Web:error");

$router->dispatch();

if ($router->error()) {
    echo var_dump($router);
    //$router->redirect("/ooops/{$router->error()}");
}

Browser other questions tagged

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