2

We are using the below bundles with Symfony2 to create a RESTful API.

new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),

We get the below error after running php composer.phar update

[2014-12-05 10:39:41] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2014-12-05 10:39:41] request.CRITICAL: Uncaught PHP Exception LogicException: "The controller must return a response (Object(Symfony\Component\Form\Form) given)." at /var/www/html/symfony2/app/bootstrap.php.cache line 3020 {"exception":"[object] (LogicException: The controller must return a response (Object(Symfony\\Component\\Form\\Form) given). at /var/www/html/symfony2/app/bootstrap.php.cache:3020)"} []
[2014-12-05 10:39:41] security.DEBUG: Write SecurityContext in the session [] []

We installed Symfony2 on our server using the below steps

//install symfony
php composer.phar create-project symfony/framework-standard-edition symfony2/

//move composer into symfony folder
cp composer.phar symfony2/composer.phar
rm composer.phar
cd symfony2

//symfony dependencies
php composer.phar require doctrine/doctrine-fixtures-bundle
php composer.phar require "friendsofsymfony/rest-bundle" "@dev"
php composer.phar require "jms/serializer-bundle" "@dev"
php composer.phar require "nelmio/api-doc-bundle" "@dev"

The API requests return a 500 server error.

I have traced the error to the below point by am unsure why it is not working.

@Annotations\View(
     templateVar = "form"
)

the ClassResourceInterface class is responsible for the above.

This may be related to this question but the solutions posted here do not work:

FOSRestBundle: The controller must return a response (Array()) given

Something is wrong with this class:

Nelmio\ApiDocBundle\Annotation\ApiDoc

Has anyone had issues with this as well?

Thank you

Community
  • 1
  • 1
pawelglow
  • 708
  • 1
  • 10
  • 20

2 Answers2

2

You should set FOS REST config in file /app/config/config.yml

For example:

#/app/config/config.yml
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: false
routing_loader:
   default_format: json
view:
    view_response_listener: 'force'
    formats:
        xml: true
        json : true
    default_engine: none
    templating_formats:
        html: true
access_denied_listener:
    json: true
allowed_methods_listener: true
0

Try to self-update your composer file before starting any new project to avoid issues.

composer self-update

or if composer is installed in your www directory:

php composer.phar self-update

then you can create a new symfony project with all the bundles you need:

composer create-project symfony/framework-standard-edition symfony2/
cd symfony2
composer require doctrine/doctrine-fixtures-bundle
composer require friendsofsymfony/rest-bundle
composer require jms/serializer-bundle
composer require nelmio/api-doc-bundle

Sometimes at this point I need to give read/write permissions to some directories such as "app/cache" or "app/bootstrap.php.cache" because my terminal uses my user but apache uses a _www user.

Then you have to register your new bundles in app/AppKernel.php

new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),

Then your Bundle NelmioApiDocBundle needs to register its own routing and config:

# app/config/routing.yml
NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

# app/config/config.yml
nelmio_api_doc: ~

Everything have to work at this point as I already did that.

  • I followed the steps and everything went smoothly as expected. The API docs show up with out any issues but when I go to any of my API calls I still get the same 500 error. – pawelglow Dec 08 '14 at 08:20
  • So you think the problem is because of these bundles instead of your own API code? can you share some of that API calls causing the 500 error? – Sergio Enrique Vargas Dec 08 '14 at 09:23