I have a small backend developed in Silex Framework. I try to make this request work on POST:
but when using mount operation only this request works:
As you can see I must add an additional trailing slash to the request.
Here is some code that doesn't work as expected:
//index.php
$app->mount("/other", new FeedbackOther());
//FeedbackOther.php
$feedbackOther->get("/", "FeedbackOtherController::index")->bind('other');
$feedbackOther->post("","FeedbackOtherController::store");
If I do something like
//index.php
$app->post('/other', "FeedbackOtherController::store");
$app->mount("/other", new FeedbackOther());
//FeedbackOther.php
$feedbackOther->get("/", "FeedbackOtherController::index")->bind('other');
The POST request works without the additional slash, but in this case I don't see the point in using mount operation.
Also I've tried using .htacces rewrite but the rewrite rule transforms the POST request in GET.
There is a difference between mounting a collection of routes and simply limiting a route to
post
. Addingmount
means that a collection of routes are being created under specific namespace, in your case that would be/other
. Meaning that the default URL for this namespace would be/other/
- trailing slash is required too. That does not apply when you define your routes to specific method, such aspost
. In short - this is the expected behaviour in bothSilex
andSymfony
as well. There was a heavy discussion about this in github a while ago, so let me copy/paste you the notes Fabien left (the author):If you're interested in the whole story - this is where the quote is taken.