diff --git a/developer_manual/basics/controllers.rst b/developer_manual/basics/controllers.rst index ad133f55d..fcecdabb8 100644 --- a/developer_manual/basics/controllers.rst +++ b/developer_manual/basics/controllers.rst @@ -482,6 +482,44 @@ Now your method will be reachable via ``/ocs/v2.php/apps//api/v JSON ^^^^ +Returning JSON is simple, just pass an array to a JSONResponse: + +.. code-block:: php + + 'hi'); + return new JSONResponse($params); + } + + } + +Because returning JSON is such a common task, there's even a shorter way to do this: + +.. code-block:: php + + 'hi'); + } + + } + +Why does this work? Because the dispatcher sees that the controller did not return a subclass of a Response and asks the controller to turn the value into a Response. That's where responders come in. + Handling errors ^^^^^^^^^^^^^^^ @@ -524,47 +562,6 @@ Modifying the content security policy --- -JSON -^^^^ - -Returning JSON is simple, just pass an array to a JSONResponse: - -.. code-block:: php - - 'hi'); - return new JSONResponse($params); - } - - } - -Because returning JSON is such a common task, there's even a shorter way to do this: - -.. code-block:: php - - 'hi'); - } - - } - -Why does this work? Because the dispatcher sees that the controller did not return a subclass of a Response and asks the controller to turn the value into a Response. That's where responders come in. - Responders ^^^^^^^^^^