symfony-forms

Symfony error when inserting new game: Entities passed to the choice field must be managed. Maybe persist them in the entity manager?

a 夏天 提交于 2019-12-11 06:08:34
问题 I'm trying to save a Game object with a Type object. When I try to save with the form I get the following error: Entities passed to the choice field must be managed. Maybe persist them in the entity manager? One Game can have 1 Type while Type can have many Games. I've managed to isolate the problem, it works fine when Game doesn't have a relation with Type so I think it has to do something with the Type object. GameController: <?php namespace AppBundle\Controller; use AppBundle\Entity\Game;

'Symfony3' - 'fosuserbundle' form - add group to user

删除回忆录丶 提交于 2019-12-11 06:01:49
问题 I use Symfony 3 with the fosuserbundle , and want to create a form, that will add multiple groups to one user. The layout is not the problem, but to building the form and submitting... Here is the sourcecode with the important parts: https://pastebin.com/tyFP8XGK The current problem is that if I have a user (in my case it is an admin) have any group, I can't add one or more groups and submit without error, BUT if I edit the admin, the groups aren't preselected in the choise, AND if I submit

When using EntityType to show a select, can't save entity from Symfony form

浪子不回头ぞ 提交于 2019-12-11 04:47:41
问题 I have two related entities in my symfony project - which are stored using Doctrine. One entity is "Advertiser" which has an id and a name. The other entity - which is causing the problem - is for a "Report" which has an id of it's own along with a field called "advertiser_id". When adding a report for an advertiser, in the Symfony form, I'm using EntityType for the advertiser_id field so that I can display a select of advertisers. That part is working great, but when I try to submit the form

Symfony2 get request url in form type extension

十年热恋 提交于 2019-12-11 02:47:28
问题 Is it possible to fetch the request URL in form type extension? I want to find out what is calling the form type extension. Thank you Jake He 回答1: As you can define from type extension as a service, i think you can inject the request 来源: https://stackoverflow.com/questions/44522444/symfony2-get-request-url-in-form-type-extension

Symfony 2 forms with validation groups, errors mapped to the wrong property?

半世苍凉 提交于 2019-12-11 02:26:39
问题 Never had this problem before. Fill the form with a phone, leaving lastname blank Submit the form (and the validation groups become Default and Create ) The error "Last name is required." is mapped on the wrong $phone field, while should be mappend to $lastName itself property Can you reproduce the same issue? $phone property is in the Create validation group, while $phone in Default implicit group: class User { /** * @Assert\NotBlank(groups={"Create"}, message="Last name is required.") * *

Symfony2 custom form

柔情痞子 提交于 2019-12-11 01:36:12
问题 I have form with checkboxes loaded from database (I use entity field type). Checkboxes are regions and districts. I have following database schema: +-----------------------------------+ | id | parent_id | name | +-----------------------------------+ | 1 | NULL | Region | +-----------------------------------+ | 2 | 1 | District | +-----------------------------------+ | 3 | 1 | Another district | +-----------------------------------+ | 4 | NULL | Another region | +------------------------------

Symfony2: problems rendering the translation-form with A2lixTranslationFormBundle and Gedmo\DoctrineExtensions Translatable

百般思念 提交于 2019-12-10 23:04:06
问题 I'm using gedmo/doctrine-translations and a2lix/translation-form-bundle: 2.*@dev to translate my entities. The translation form always renders a Field and Content but my entity itself doesn't contain a Field or Content field. The form type $builder->add('translations', 'a2lix_translations'); 回答1: The 2.0 version of the TranslationFormBundle isn't compatible with the current gedmo/doctrine-extensions version. See the bundle's upgrade notes . You'll need to use the currently unstable branches

Symfony Forms - How to Change a CollectionTypes Items labels

六月ゝ 毕业季﹏ 提交于 2019-12-10 18:29:52
问题 This is my first question on stackoverflow; until now I just looked for answers for my issues and found them. But now it seems that I have one that nobody or at least no one here stumbled across. About my problem: In my Class FieldType extends AbstractType I want to change the labels of CollectionType items. This works for all contained items, but I want to set the labels individually: $translations = $builder->create("translations", CollectionType::class, array( "label" => "Translations",

Symfony2 Form Entity to String Transformer Issue

拈花ヽ惹草 提交于 2019-12-10 18:04:30
问题 I am using Symfony 2.1.3-DEV and trying to accomplish transforming entity to string (ID of some kind) and then back from string to entity when form is submitted. The issue is the same if I'm using the transformer given in the cookbook: http://symfony.com/doc/master/cookbook/form/data_transformers.html Controller code: $task = $entityManager->find('AcmeTaskBundle:Task', $id); $form = $this->createForm(new TaskType(), $task); // so $task->issue is Issue object I get this error: The form's view

Symfony2: how to get config parameters in Form classes

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:48:44
问题 If I am inside a controller, I can easily read the config parameters using: $this->container->getParameter('profession'); But when I am in some other class, say a Form type, how can I get hold of the config parameters? $container = new Container(); $container->getParameter('profession'); The above code shouldn't and doesn't work. 回答1: Another similar solution is make your form type a service and inject the needed parameters. Then all your controller needs to do is to grab the service.