Skip to content

Controller methods are call twice on every request #96

@dieume-n

Description

@dieume-n
"phroute/phroute": "^2.1",

bootstrap.php

require_once "../vendor/autoload.php";

use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
$router = new RouteCollector();
$router->get('/', ['App\Controllers\HomeController', 'index']);

$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
try {
    $response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
} catch (HttpRouteNotFoundException $e) {
    die(var_dump($e));
} catch (HttpMethodNotAllowedException $e) {
    die(var_dump($e));
}

echo $response;

HomeController.php

namespace App\Controllers;

class HomeController
{
    public function index()
    {
        return "Hello";
    }
}

every time i make a request to any of the endpoints, the controller method is called twice. Has anyone encounter this issue? if so, how did you solve it?

output
Capture

debug back_trace
Annotation 2020-01-31 151139

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions