symfony-forms

Render controller and get form errors from child

别等时光非礼了梦想. 提交于 2019-12-13 02:26:50
问题 I have a template where I render a widget which contains a form: {{ render(controller('ApplicationDemoBundle:Demo:newWidget', {'demo' : entity })) }} The newWidgetAction calls a createAction: public function createAction(Request $request) { $entity = new Demo(); $form = $this->createCreateForm($entity); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('demo_show',

Symfony: Only one file entity and different validation rules for each association?

耗尽温柔 提交于 2019-12-13 02:25:14
问题 In my current project, I decided to create only one translatable File entity and reuse it for all image/document properties I have. For the translations, I uses Knp Doctrine Behaviors Translatable. So here is the code. The file class: class File { use ORMBehaviors\Translatable\Translatable; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; public function __toString() { return (string)$this->id; } /** * Get id * *

Handling a complex Symfony2 form with multiple entities relationship

天涯浪子 提交于 2019-12-13 01:43:46
问题 I have a form (still not finished and is missing many fields) that is handled as a wizard with steps, in which fields from multiple entities are handled. This is the form itself: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('tipo_tramite', 'entity', array( 'class' => 'ComunBundle:TipoTramite', 'property' => 'nombre', 'required' => TRUE, 'label' => "Tipo de Trámite", 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder

Catchable Fatal Error in form event subscriber using Symfony 2.3

假装没事ソ 提交于 2019-12-13 01:43:40
问题 After updating to Symfony 2.3 from 2.1, there is a strange message when I am trying to create a form : Catchable Fatal Error: Argument 1 passed to msgr\ProfileBundle\Form\EventListener\AddNameFieldSubscriber::preSetData() must be an instance of Symfony\Component\Form\Event\DataEvent, instance of Symfony\Component\Form\FormEvent given in /xxxxxx/aaas/src/msgr/ProfileBundle/Form/EventListener/AddNameFieldSubscriber.php line 29 These are the usual suspects : ProfileType.php <?php namespace aaas

How can I render an entity (choice <select>) field as a <ul> field in Twig?

房东的猫 提交于 2019-12-13 01:35:11
问题 Symfony renders an entity field type like a choice dropdown - a select , basically. However, the CSS framework that I'm using defines a sort of 'select' as a ul and li as the options. The Custom Field Type documentation gives no help on this scenario. I'm converting my code from manual HTML rendering of the form dropdown to symfony form's version using twig and form_widget() . However, I want a ul and li instead of a select . The manual way of creating my dropdown is: <ul class='dropdown-menu

symfony 4 form collection entity with file type create

梦想与她 提交于 2019-12-12 22:28:02
问题 How to create and upload the document using entity where fileType field is embedded in parent form via collectionType. I did read the documentation Symfony Upload. But didn't manage to accomplish this. Always get this error "Type error: Argument 1 passed to App\Service\FileUploader::upload() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile, instance of App\Entity\Attachment given". Below is my Invoice entity class Invoice { /** * @ORM\Id() * @ORM\GeneratedValue() *

Validate UniqueEntity for One-To-Many, Unidirectional with Join Table [Symfony2]

三世轮回 提交于 2019-12-12 18:14:00
问题 I have 2 mapped entities , Box class Box{ //[...] /** * @ORM\ManyToMany(targetEntity="Candy", cascade={"remove"}) * @ORM\OrderBy({"power" = "DESC"}) * @ORM\JoinTable(name="box_candies", * joinColumns={@ORM\JoinColumn(name="box_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="candy_id", referencedColumnName="id", unique=true)} * ) */ private $candies; } And Candy class Candy { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM

Accessing PHP Array Object Protected Property

南楼画角 提交于 2019-12-12 08:56:03
问题 I am trying to upload multiple files in Symfony2. I am trying to access the following request object, but I am unable get the parameters property. How do I reach the files one by one to upload them. The error I get: Fatal error: Cannot access protected property Symfony\Component\HttpFoundation\FileBag::$parameters in /var/www/File/src/Webmuch/FileBundle/Entity/File.php on line 66 Request Object: Symfony\Component\HttpFoundation\FileBag Object ( [parameters:protected] => Array ( [file] =>

Symfony twig how to add class to a form row

流过昼夜 提交于 2019-12-12 07:12:25
问题 I am building a project in Symfony 2.3 using Twig. I want to add a class to the form row block. I am using a form theme file which contains: {% block form_row %} <div class="form-row"> {{ form_label(form) }} {{ form_widget(form) }} {{ form_errors(form) }} </div> {% endblock %} Now some of my form rows I want to add an extra class form-row-split . I can't figure out how to do this properly. The way I have it almost-working is: {% block form_row %} {% set attr = attr|merge({'class': 'form-row'

SYMFONY custom CONSTRAINT -> Pass variable to a custom CONSTRAINT / How CONSTRAINT binded to a form field can OVERRIDE CONSTRAINT in ANNOTATION

家住魔仙堡 提交于 2019-12-12 07:05:33
问题 My goal: I built a custom constraint in SYMFONY, I needed to pass a variable to that constraint. The context: The constraint do a check if a value is unique in the DB, if it is not, it raises a CONSTRAINT alert. That works alright when the FORM is used to create a new tuple in the DB but if it is an edit it raises an exception which should be bypass by checking that the value already existing, exists for the tuple Id being edited . Hence I needed to pass the Id of the tuple being edited to my