Respect \ rest does not work when trying to implement in my project

0

I'm testing a web application, but I need to implement the use of routing and I found it better to work with Respect \ rest. I followed all the instructions for using the class, but I can not print if I want a Hello world on the screen, what is wrong?

Index.php file

  use Respect\Rest\Router;
  chdir( __DIR__ . '/..');
  require 'vendor/autoload.php';

  $router = new Router();
  $router->get('/','Hello World');

I made the installation of class Respect \ Rest via composer, but I've been testing for a long time nothing happens.

Here is my composer.json

  {

    "autoload": {
       "psr-4": {
         "App\": "src/App"
       }
    },
    "require": {

    "respect/rest": "^0.6.0"
    }
  }
    
asked by anonymous 21.04.2016 / 12:01

1 answer

0

I believe the problem is that you include autoload.php , which in turn includes all dependencies in your project.

I would do it this way:

require_once(__DIR__ . '/vendor/autoload.php');

use Respect\Rest\Router;

$router = new Router();
$router->any('/', function() {
    return 'Funcionou.';
});

PS: This is the directory structure I worked with:

.
├── composer.json
├── composer.lock
├── index.php
└── vendor
    ├── autoload.php
    ├── composer
    └── respect
    
09.05.2016 / 13:43