-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slim/Crud integration sends request body as an array #567
Comments
Hi, Thank you for your bug report. I really appreciate the effort and the quality of your issues.
Can you disable your middlewares and see whether or not this is specific for your implementation? Kind regards, Maurits |
Just to double check on what you are asking...you would like for me to pass the outside request directly to the CRUD without going through my Slim application first? Also, so that you can see what I'm currently doing as a bypass that works, I'm attaching the relevant code. use \Psr\Http\Message\RequestInterface; $requestBody = $request->getParsedBody(); $response = $api->handle($request); |
Hi Karl. This is what I wanted to know, thank you. I will try to reproduce and come up with a solution (if I can). Kind regards, Maurits |
I have found the reason, SlimPHP does not allow you to send objects, see: https://github.com/slimphp/Slim/blob/3.x/Slim/Http/Request.php#L200 IMHO that line should have read (leaving out the second parameter):
This is a mistake on their side (in Slim 3) and it is no longer present in Slim 4. Nevertheless I was able to implement a workaround (see commit). Can you test it? |
I have released v2.4.1 for you. It should have the (improved) workaround. |
You may also read about SlimPHP 4 support on my blog: https://tqdev.com/2019-automatic-api-slimphp-4 Please reopen this issue if you are still experiencing problems. |
This is working for me as expected (double checked). I will upgrade to Slim 4, though, as well, wasn't paying enough attention to that update. Thanks for being so diligent in your tracking this down when there was no reason for you to know I'd be behind on SLIM versioning and I wouldn't expect you to keep your code up to date with a previous version. Thanks for all of this, learned a lot today in my interactions back and forth with you and really really appreciate your time! |
Thank you for your kind words, appreciated! |
My current project begins with a request going through Slim and middleware passing the request into the CRUD. The "getParsedBody()" of the Request object is an array, at this point, not an object...so assuming the request comes in as
POST /records/posts
Content-Type: application/json
{"user_id":1,"category_id":1,"content":"test"}
by the time it gets to the CRUD and specifically to https://github.com/mevdschee/php-crud-api/blob/master/src/Tqdev/PhpCrudApi/Controller/RecordController.php#L75-L80, the record is an array..so on line 80, this will be true and it won't send all the data on to $this->service->create() as expected.
I have some work-arounds for this, but just not sure if this is an error in my setup or just a feature, that isn't working well for me.
Thank you, I really like how versatile the CRUD is.
The text was updated successfully, but these errors were encountered: