symfony-forms

using sonata_type_collection against a custom form type instead of a property/relationship with another entity

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:31:27
问题 is it possible to use sonata_type_collection against a custom form type instead of a property/relationship with another entity? Something like this: $formMapper->add('foo', 'sonata_type_collection', array('type' => new \myVendor\myBundleBundle\Form\Type\BlockType() )); Which throws me the following error The current field `contingut` is not linked to an admin. Please create one for the target entity : `` EDIT: Something like this did the trick: $formMapper->add('contingut', 'collection',

symfony2 form choice and mongodb

放肆的年华 提交于 2019-12-05 02:31:59
When using Entity we can load choices from Entity via form field type entity $builder->add('group', 'entity', array( 'class' => 'Fist\CoreBundle\Document\Group', )); but when using mongodb document what is the best way to inject select options from Document? in my case load all Groups from Group document. Is there better way to do that than passing to form constructor? Thank you all The Doctrine MongoDB ODM equivalent of EntityType is Symfony\Bundle\DoctrineMongoDBBundle\Form\Type\DocumentType . DocumentChoiceList , DocumentsToArrayTransformer , and DocumentToIdTransformer are also included in

Symfony2 choice field not working

扶醉桌前 提交于 2019-12-05 01:17:15
问题 I asked a question here How to use Repository custom functions in a FormType but nobody anwsered, so i did a little digging and advanced a little but i still get this error: Notice: Object of class Proxies\__CG__\Kpr\CentarZdravljaBundle\Entity\Category could not be converted to int in /home/kprhr/public_html/CZ_Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php line 457 Now this is how my CategoryType looks like: <?php namespace Kpr

Symfony2 allocates uploaded file to memory

痞子三分冷 提交于 2019-12-05 01:05:50
问题 While uploading a file bigger than post_max_size in Symfony, the uploaded file is allocated in the memory. Fatal error: Allowed memory size of 150994944 bytes exhausted (tried to allocate 84627994 bytes) in /Applications/MAMP/htdocs/Symfony/vendor/symfony/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php on line 28 Why is symfony trying to allocate a file to the memory on POST? 1/ php.ini file_uploads = On upload_tmp_dir = /Applications/MAMP/tmp/php upload_max_filesize = 32M

Overriding the User Admin Form

做~自己de王妃 提交于 2019-12-05 00:47:47
问题 I'm trying to override the SonataUser/Admin/Model/UserAdmin 's configureFormFields() because I need to remove some default fields from the admin form. So I have copied the file vendor/bundles/Sonata/UserBundle/Admin/Model/UserAdmin.php in my bundle app/Application/Sonata/UserBundle/Admin/Model/UserAdmin.php and modified it. Then declared it as a service: # app/application/Sonata/UserBundle/Resources/config/services.yml services: application_user.registration.form.type: class: Application

Get value of a field not declared in FormType

元气小坏坏 提交于 2019-12-04 22:56:00
I have a form declared in nameType.php and the view render all field but I want add another field manually. Form: <form action="{{ path('create') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input type="text" value="2"> </form> And get the values in the controller: $form->bindRequest($request); How can I collect the value of the input in the controller? If you are trying this because the form is linked to your entity field you can add a field to FormType as not mapped. Then you do not need getters and setters on your entity. ->add("inputName", "text", array("mapped"=

Form Collection Error

独自空忆成欢 提交于 2019-12-04 19:45:26
问题 I am trying to take one form type and display it however times i need for the user to upload a patch upload at one time. So say 30 files to uploaded, 30 forms on the page. I am receiving this error: The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class MS\CoreBundle\Entity\Photo. You can avoid this error by setting the "data_class" option to "MS\CoreBundle\Entity\Photo" or by adding a view transformer that transforms an

How can I check whether the supplied CSRF token is invalid in Symfony2?

一个人想着一个人 提交于 2019-12-04 18:01:40
问题 I have created a Symfony2 form and bound it to the Request. I need to explicitly ensure whether the CSRF token is valid/invalid before proceeding with the rest of the form. $form['_token']->isValid() throws OutOfBoundsException with message "Child _token does not exist." I can still verify that the rendered form contains _token field. In case that CSRF value is invalid, $form->isValid() returns false. What am I missing here? Update 1: Controller (partial): private function buildTestForm() {

Symfony2: Could not load type “MyType”

心已入冬 提交于 2019-12-04 16:33:29
问题 I am trying to create a new field type and add it to a form class in Symfony 2. I have created a class called MyType (for testing purpose) and when I want to add it to a form class I get the error: Could not load type "MyType". I guess I must tell Symfony to load that type, but I don't know how! 回答1: You have register your form in the section services of your config.yml services: my_type_form: class: sf\MyTypeBundle\Form\MyType tags: - { name: form.type } Then you can call it from your

Accessing PHP Array Object Protected Property

雨燕双飞 提交于 2019-12-04 11:52:00
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] => Array ( [0] => Symfony\Component\HttpFoundation\File\UploadedFile Object ( [test:Symfony\Component