symfony-forms

symfony filter change behaviour from [field=value] to [field LIKE %value%]

随声附和 提交于 2019-12-08 09:45:45
问题 In my filter, a field's behaviour is to search in the DB table for a row that has the value of the field equal to the value provided in filtering form. I'd like to change its behavior to search in DB table for a row/rows that have field value matching to that provided in the form( %LIKE% ). I know it can be done by adding a addFieldnameColumnQuery method to the filter class but What I want to know is, is there another way? The field happens to be a foreign key and I want it to work like a

pagination in symfony 4 using KnpPaginatorBundle

岁酱吖の 提交于 2019-12-08 08:32:44
问题 Attempted to load class " KnpPaginatorBundle " from namespace " App\Knp\Bundle\PaginatorBundle ". Did you forget a " use " statement for " Knp\Bundle\PaginatorBundle\KnpPaginatorBundle "? 回答1: Just add class namespace of KnpPaginatorBundle : in config/bundles.php : <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], *************************************************************** **************

Symfony 1.4 embedded form fields at the same indent

◇◆丶佛笑我妖孽 提交于 2019-12-08 06:44:17
问题 I have two models in my Symfony application. First one is Blog: Blog: columns: name: { type: string(20), notnull: true, unique: true } title: { type: string(255), notnull: true } description: { type: string(255), notnull: true } admin_id: { type: bigint, notnull: true } relations: User: class: sfGuardUser local: admin_id ... As you can see this model has a one-to-one relationship with sfGuardUser. I want the registration of these two take place in one form. So I changed the BlogForm class and

Create form dynamically in Symfony 2

懵懂的女人 提交于 2019-12-08 06:01:37
问题 A simple question: I have one form, it returns one number and I need create this number of labels in Controller. I try: $form2 = $this->createFormBuilder(); for($i = 0; $i < $num; $i++) { $name = 'column'.$i; $form2->add($name,'number'); } $form2->getForm(); I think it should very simple, but i can't.. 回答1: Yes, you can do it with an array / hash map instead of a real object. Here is an example : // Create the array $dataObj = array(); $dataObj['data1'] = ''; $dataObj['data2'] = 'default'; //

Default Options for symfony 2 forms are being overridden not merged

别说谁变了你拦得住时间么 提交于 2019-12-08 04:55:03
问题 I have a custom form type that defines some default attr options: public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'invalid_message' => 'The selected image does not exist', 'attr'=>array( 'data-image-picker'=>'true', 'data-label'=>'Pick Image' ), )); } However when i use this custom form type the entire attr array is replaced with what is defined. $builder->add('logo','image_picker',array( 'attr'=>array( 'data-label'=>'Logo' ), )); When the

Accessing a form field from a subscriber (of a form event) in Symfony2

你。 提交于 2019-12-08 00:17:03
问题 I'm following the tutorial How to Dynamically Generate Forms Using Form Events. I'm stuck on the creation of AddNameFieldSubscriber : $subscriber = new AddNameFieldSubscriber($builder->getFormFactory()); My question is simple: how FormFactory can access and modify an arbitrary form field previously created by the $builder ? And why we are passing the FormFactory instead of the $builder itself? Assuming we have just two fields ("name" and "price") in the builder : class ProductType extends

How to disable html5-validation for specific buttons in symfony 2.3

被刻印的时光 ゝ 提交于 2019-12-08 00:16:52
问题 I have a form with three buttons. One for adding objects, one for deleting and one for editing objects. I now want to disable html5-validation in the add-button using the new form buttons introduced in Symfony 2.3. Is this possible or do I have to create a new button type? How could I do that? 回答1: All you need to do is to add the html attribute novalidate or novalidate="novalidate" to the element. You can do this same way you would add any other attribute from either the form type of the

Symfony2 Cloning entities with collections and entity field type

孤街浪徒 提交于 2019-12-07 21:08:10
问题 I have object A which contains a collection of objects B which in turn contain a collection of objects C which again contains a collection of object D. I need to retrieve object A from DB, create a form from it, change some values in fields of the form (in the future also add and remove elements from the collections) and persist on DB a new object A with all the appropriate references to the new B, new C and new D. The object CVC below is my A. If I do: $storedCVC = $this->getDoctrine() -

How to add an Event Listener to a dynamically added field using Symfony Forms

我的梦境 提交于 2019-12-07 20:25:20
问题 I am using event listeners to dynamically modify a form. I want to add another event listener to a field that was added dynamically. Im not sure how to accomplish this. public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('first_field','choice',array( 'choices'=>array('1'=>'First Choice','2'=>'Second Choice') )); $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'preSetData')); $builder->get('first_field')->addEventListener(FormEvents::POST

Making a A2lix translation field required in the front end in a Symfony form

守給你的承諾、 提交于 2019-12-07 19:07:17
问题 Is there a way to make a A2lix translation field required and validated through the front-end in a Symfony form? I have tried adding a property of presentation and translations to my validation.yml file, but to no avail. I find that when I don't enter anything in the translation field the form doesn't submit, but nothing happens. No FE or BE error. My form: /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', 'a2lix