Respect Rest does not work when trying to implement in my project

Asked

Viewed 44 times

0

I am testing a web application, but I need to implode the use of hoarding and I thought better to work with Respect Rest. I followed all the instructions of use of the class, but I can not print if you want a 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 installed the 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"
    }
  }

1 answer

0

I believe the problem lies in the inclusion of autoload.php, which in turn includes all dependencies in your project.

I’d 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

Browser other questions tagged

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