3

Just created a new project with symfony2 and installed FOSRestBundle. Controller example:

<?php

namespace ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\FOSRestController;


class TestController extends FOSRestController
{
    public function TestAction()
    {
        $data = array ('1', '2', '3', 'four'); // get data, in this case list of users.
        $view = $this->view($data, 200)
            ->setTemplate("ApiBundle:Test:test.html.twig")
            ->setTemplateVar('test')
        ;

        return $this->handleView($view);       
    }

}

Got error message:

You have requested a non-existent service "fos_rest.view_handler".

Does anyone have an idea about this?

Supervision
  • 1,683
  • 1
  • 18
  • 23

1 Answers1

3

In your AppKernel, be sure you have the following:

// app/config/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\RestBundle\FOSRestBundle(),
    );
}

You surely forgotten this step.

chalasr
  • 12,971
  • 4
  • 40
  • 82