A
A
anboo2016-02-25 20:18:22
symfony
anboo, 2016-02-25 20:18:22

Unable to find template FOSUserBundle?

routing:

backend_users_api:
  type: rest
  resource: "@BackendUserBundle/Controller/Api/UserController.php"
  prefix: /

config:
sensio_framework_extra:
    view:
        annotations: false
    router:
        annotations: true

fos_rest:
  format_listener:
      rules:
          - prefer_extension: false
  routing_loader:
      default_format: json
      include_format: false
  view:
      view_response_listener: force

controller:
/**
 * Class UserController
 * @package Backend\UserBundle\Controller\Api
 * @Route("/api")
 */
class UserController extends FOSRestController
{
    /**
     * @var EntityManager
     * @DI\Inject("doctrine.orm.entity_manager")
     */
    public $em;

    /**
     * @Rest\Route("/all")
     * @Rest\View()
     */
    public function allAction()
    {
        $users = $this->em->getRepository('AppBundle:User')->findAll();

        return array('users' => $users);
    }

When requesting /api/data, it gives 500 and an error: FOSUserBundle:Api\User:all.html.twig

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2016-02-26
@prototype_denis

Well, something like this...

fos_rest:
    body_listener: true
    body_converter:
        enabled: true
    format_listener:
        rules:
            - { path: '^/api',  priorities: ['json'], fallback_format: json, exception_fallback_format: json, prefer_extension: true }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question