Problem with the routes that I include in the index of my REST API

1

Hi, I am developing a API with slim framework 3 that connects to a base de datos local. The problem is the following within my index.php I pass the rutas where are the queries to the database. The problem is that I can not include more than one ruta . For example, if I pass the path require '../app/route/usuario.php'; and require '../app/route/persona.php'; , when I go to the browser if I want to see the users it returns the typical page no found and if I want to see the people it returns the elements of the person table. If I delete the second ruta of my index , and I try to see the usuarios again in the browser, it shows them without problem.

index.php

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php';
require '../app/config/db.php';

$app = new \Slim\App;
require '../app/route/usuario.php';
require '../app/route/persona.php';

$app->run();

user.php     

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$app = new \Slim\App;

$app->group('/usuario/', function () {

$this-> get('', function(Request $request, Response $response){

$sql = "select * from usuario";

try{
    $db = new db();

    $db = $db->connect();

    $stmt = $db->query($sql);
    $usuario = $stmt->fetchAll(PDO::FETCH_OBJ);
    $db = null;
    echo json_encode($usuario);

} catch(PDOException $e){
    echo '{"error": {"text": '.$e->getMessage(). '}';
}    
});

persona.php     

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$app = new \Slim\App;

$app->group('/persona/', function () {

$this-> get('', function(Request $request, Response $response){

$sql = "select * from persona";

try{
    $db = new db();

    $db = $db->connect();

    $stmt = $db->query($sql);
    $persona = $stmt->fetchAll(PDO::FETCH_OBJ);
    $db = null;
    echo json_encode($persona);

} catch(PDOException $e){
    echo '{"error": {"text": '.$e->getMessage(). '}';
}
});
    
asked by Germanccho 26.01.2018 в 12:49
source

0 answers