I'm using FOS Rest Bundle to build an Api, the problem is that every time I try to return anything I get the error message: "Unable to find template" I don't really want to render a template, but to serialize an entity that I have.
Here is my code:
routing.yml:
acme_api_register:
pattern: /user
defaults: { _controller: AcmeApiBundle:User:post, _format: json }
requirements:
_method: POST
controller.php:
<?php
namespace Acme\ApiBundle\Controller;
use Acme\ApiBundle\Entity\Patient;
use Acme\ApiBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\Controller\Annotations\View;
//use FOS\RestBundle\View\View;
class UserController extends Controller
{
/**
* @View()
*/
public function postAction()
{
$user = new Patient();
$user->setName("Daniel");
$user->setLastName("My lastName");
$user->setEmail("[email protected]");
return $user;
}
}
and my app/config.yml
sensio_framework_extra:
view: { annotations: false}
router: { annotations: true }
fos_rest:
format_listener:
rules:
- prefer_extension: false
routing_loader:
default_format: json
view:
view_response_listener: force
I would appreciate any help a lot!
PD:
composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/rest-bundle": "1.1.*",
"jms/serializer-bundle": "0.13.*"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "symlink",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.4-dev"
}
}
}