Ravikumar Jogu Ravikumar Jogu - 9 days ago 6
PHP Question

Could not execute delete route in Silex framework

I am trying to build REST for user resources using silex framework.

for the routes: Update and Delete, I am unable to execute corresponding actions.

Update

$app->put(
'/users/{id}',
function (Application $app, Request $request) {
return "Updated";
}
);


Delete

$app->delete(
'/users/{id}',
function (Application $app, Request $request) {
return "Deleted";
}
);


What is wrong with such a solution?

Answer

Controller functions must return a response, otherwise the framework will throw a LogicException:

The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?

For a "hello world" controller you can use:

return new \Symfony\Component\HttpFoundation\JsonResponse([]);