1

I'm trying to make action like in FOSRestBundleByExample/blob.

My action:

    public function putManagerToMpkAction()
{
    $view = View::create();
    $view->setStatusCode(404)->setData("Error Message");
    return $view;
}

But i have and response:

The controller must return a response (Object(FOS\RestBundle\View\View) given).

I have found i can change view_response_listener to true in my config, but then i have:

Unable to find template "".

Any ideas?

Thanks Kamil

2
  • Does your controller extend the FOSRestController? Commented Oct 7, 2015 at 14:14
  • Yes, FOS\RestBundle\Controller\FOSRestController Commented Oct 7, 2015 at 14:21

1 Answer 1

3

I think you want to do :

return $this->handleView($view);

Source : http://symfony.com/doc/current/bundles/FOSRestBundle/2-the-view-layer.html

Sign up to request clarification or add additional context in comments.

4 Comments

After that Symfony styll are looking for template named as a method. I my method is named postManagerAction symfony are looking for vied named "postManager.twig.html". > Unable to find template "". Can I disable this and just return $this->handleView()?
Well, you need to have a template somehow since you are sending a response. The application can't guess how you want to render your data... so you have to create a template.
But if I don't want to show anything? I just want to return status 200 if everything is OK, or json data.
Well, don't set any data then view()->setStatusCode(200)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.