1

I hope you're good.

I'm working on an inventory system and I'm using FlightPHP to create the REST because is very light and i used to work in another projects before.

But right now, I have a trouble with that framework and I tried to find a possible solution for that issue but I couldn't.

First of all, I'll paste part of the code that I'm using

Flight::route('PUT /proveedores/', function() {

    $put_request = Flight::request();

    $Proveedor = new Proveedor(
        $put_request->data->RazonSocial,
        $put_request->data->RFC,
        $put_request->data->Domicilio,
        $put_request->data->Numero,
        $put_request->data->Colonia,
        $put_request->data->Municipio, 
        $put_request->data->Estado,
        $put_request->data->Pais,
        $put_request->data->CodigoPostal,
        $put_request->data->CondicionPago,
        $put_request->data->Plazo,
        $put_request->data->CorreoElectronico,
        $put_request->data->Contrarrecibos,
        $put_request->data->Observaciones
    );

    $Proveedor->setID($put_request->data->IDProveedor);

    $Updated = ProveedoresController::updateProveedor($Proveedor);

    if($Updated) {
        Flight::halt(200);
    } else {
        Flight::halt(500);
  }
});

As you can see, the code is easy to understand. I have a PUT method working within a /proveedores/ path and after that, I'm getting the request to read each field of the HTTP packet (I don't want to specify the code below because I tested it and the issue is not in that section).

The trouble is when I'm getting the data from the Flight::request method, I'm getting NULL values. I tested it with POSTMAN and with my application and I still having that issue. I don't know what is happening, because with the another methods I'm using (such as GET, POST and DELETE) are working properly.

P.D. Sorry if my english is bad, I hope you'll understand my situation and help me with that trouble

1 Answers1

0

Are you sure you are sending the request as application/json content type?

If so, try with:

$body = Flight::request()->getBody();

Source: Flight Docs

iaserrat
  • 37
  • 1
  • 7
  • Hi @iaserrat... That is working for me partially because the getBody generates a String. So, is there a method or a way to read the raw information generated by getBody? I don't know if that's helpful but I'm not specifying headers into my postman nor my app. Thank you for your time – Carlos Garnica Jr. Jan 03 '16 at 07:57
  • I want to update my last comment. I added the application/json header into the PUT package (using postman) and when i try to get the $put_Request->data it still showing me null values. – Carlos Garnica Jr. Jan 03 '16 at 09:36