fosrestbundle

FOSRestBundle: How to Avoid Automatic Pluralization of POST /login Route?

旧街凉风 提交于 2019-12-12 09:57:02
问题 I have this Action to handle the user login also via REST api call: /** * Login Action * * @param Request $request */ public function postLoginAction(Request $request) { This is what php app/console router:debug shows me: en__RG__post_login POST ANY ANY /api/1/logins.{_format} In this case the automatic pluralization to " logins " is not so nice... any ideas how to get only " login "? 回答1: You can manage default route pluralization by overriding fos_rest.inflector.doctrine service. refer this

FOSOAuthServerBundle + FOSRestBundle + CamelCase = Not authenticating

佐手、 提交于 2019-12-12 05:19:04
问题 I have been working on my server in Symfony 2.8, building a rest api which returns json objects in camelCase style, the problem now is that when I integrate the OauthServer bundle it lauches this error Invalid grant_type parameter or parameter missing" , I understand that this happens because I am using the array_normalizer: fos_rest.normalizer.camel_keys body listener in my fos_rest configuration. Here my code in configuration.yml : fos_rest: #other listeners# body_listener: array_normalizer

Symfony2 injecting Doctrine Dbal as service on constructor

痴心易碎 提交于 2019-12-12 04:47:19
问题 Trying to pass a Doctrine dbal connection to my construct in a controller. I am following this link to do it but it is not working: How do you access Doctrine DBAL in a Symfony2 service class? Here is my service inside app/config/config.yml services: form1: class: Test\TestBundle\Controller\FormController arguments: [@doctrine.dbal.form1_connection] Here is my controller with construct namespace Test\TestBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle

Format returning date format on Symfony2 FOSRestBundle

岁酱吖の 提交于 2019-12-11 12:01:52
问题 Is there any way to change the returning date format on a Webservice built with FOSRestBundle in Symfony2? For example, this is my actual return: {"id":9,"nome":"Guilherme","rg":"0000000000","cpf":"000.000.000-00", "nascimento":"1989-06-24T00:00:00+0200" ,"genero":"M"} I want to change to this: {"id":9,"nome":"Guilherme","rg":"0000000000","cpf":"000.000.000-00", "nascimento":"1989-06-24" ,"genero":"M"} Thanks. 回答1: It's just to add this annotation to the property: @Type("DateTime<'Y-m-d'>")

How to override register form FosUserBundle?

风流意气都作罢 提交于 2019-12-11 11:44:38
问题 I want to override some of FOSUserBundle forms ( registration form ) So I followed the documentation and I cant understand why I keep getting the same error : Attempted to load class "RegistrationFormType" from namespace "OC\UserBundle\Form\Type". Did you forget a "use" statement for "FOS\UserBundle\Form\Type\RegistrationFormType"? 500 Internal Server Error - ClassNotFoundException. These are my files: RegistrationFormType.php: <?php namespace OC\UserBundle\Form\Type; use Symfony\Component

Form bind not binding request to form in Symfony 2.1+FOSRestBundle

China☆狼群 提交于 2019-12-11 10:59:17
问题 I'm implementing rest API using FOSRestbundle. Now say for POST request i'm getting request parameters properly like: Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( [rank] => 12 [city] => 1345 [comment]=> 'safd' ) ) My post action code is : /** * @Rest\View */ public function newAction(){ $rank= new Rank(); $form = $this->createForm(new RankType(), $rank); $form->bind($this->getRequest()); if ($form->isValid()) { //. $user->flush(); $em = $this-

Symfony2 & FOSRestBundle: Getting UUID packed in a BINARY(16) field from MySQL

一曲冷凌霜 提交于 2019-12-11 07:46:48
问题 I am facing a weird problem relating to UUIDs. I have developed a REST API using Symfony2+FOSRestBundle+JMSSerializer. As I need to update some tables from two sources I thought of using UUID as primary key for one entity. I did a doctrine:mapping:import to generate entities in my Symfony project. Everything correct. I ended up with the following entity (only exposing the key field and generated getter for simplicity): <?php namespace Stardigita\TgaAPIBundle\Entity; use Doctrine\ORM\Mapping

Custom exception with fosrest bundle in symfony2

本秂侑毒 提交于 2019-12-11 06:36:32
问题 Hi I am trying to add custom exception but it is not working now my response is like:(also the breakdown debuger is not trigger that class) { "error": { "code": 500, "message": "Required Parameter Missing" } } this is the default exception of fos rest I added new class that wrapp the exception class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface { public function wrap($data) { $exception = $data['exception']; $newException = array( 'success' => false, 'exception' => array

Symfony - CSRF token is invalid - FosRestBundle

最后都变了- 提交于 2019-12-11 05:15:00
问题 I'm using Symfony and FosRestBundle. When I want to simply test my rest api, I got this : The CSRF token is invalid. Please try to resubmit the form. /** * @example ["titre", "short description", "description", "2016-10-10", 200, "with complete data"] * @example ["titre", "short description", "description", "2016-10-31", 200, "with complete data"] */ public function editNewsTest(ApiTester $I, Example $example) { $I->wantTo('edit a news (' . $example[5] . ')'); $I->haveHttpHeader('Content-Type

Symfony2 REST API - Partial update

China☆狼群 提交于 2019-12-11 02:04:26
问题 I'm building a REST API with FOSRestBundle in Symfony2. I'm using forms to create and update entities with Doctrine2. Everything works fine if I send all form fields. Example: {"first_name":"Pi","last_name":"Wi"} The person is inserted fine but now I want to update only the last name. {"last_name":"Wi"} The problem is that the first name is empty after the update because the form updates the entity with an "null" value (because it isn't given). Is it possible to just update the last name and