simplethings / simplethingsformserializerbundle Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED]
[DEPRECATED]
I'm currently implementing a Closure table tree model and my File
object has a $parent
property which points to itself. I need this in order to correctly render the File
parent nameon the client-side.
To serialize this information, I need to add this field to the FileType
form as a new FileType
form type. This causes a stackoverflow.
class FileType extends AbstractType
{
$builder
->add('name')
->add('parent', new FileType, array('serialize_only' => true))
;
}
Simplified example:
{
category: "folder"
name: "sample"
parent: {
category: "folder"
name: "home"
}
Stacktrace:
( ! ) Fatal error: Maximum function nesting level of '300' reached, aborting! in vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/Options.php on line 179
Call Stack
# Time Memory Function Location
1 0.0001 243736 {main}( ) ../app_dev.php:0
2 0.0045 1206520 Symfony\Component\HttpKernel\Kernel->handle( ) ../app_dev.php:28
3 0.1373 3378576 Symfony\Bundle\FrameworkBundle\HttpKernel->handle( ) ../bootstrap.php.cache:610
4 0.1374 3380328 Symfony\Component\HttpKernel\HttpKernel->handle( ) ../bootstrap.php.cache:1555
5 0.1374 3380392 Symfony\Component\HttpKernel\HttpKernel->handleRaw( ) ../bootstrap.php.cache:1383
6 0.3574 8257856 call_user_func_array ( ) ../bootstrap.php.cache:1419
7 0.3575 8258280 MyApp\FileBundle\Controller\DefaultController->putFileAction( ) ../bootstrap.php.cache:1419
8 0.3685 8656272 Symfony\Bundle\FrameworkBundle\Controller\Controller->createForm( ) ../DefaultController.php:54
9 0.3690 8729192 Symfony\Component\Form\FormFactory->create( ) ../Controller.php:156
10 0.3736 9065128 Symfony\Component\Form\FormBuilder->getForm( ) ../FormFactory.php:36
11 0.3913 9410904 Symfony\Component\Form\FormBuilder->getForm( ) ../FormBuilder.php:201
(...)
282 1.9549 43960328 Symfony\Component\Form\FormBuilder->resolveChildren( ) ../FormBuilder.php:196
283 1.9558 43972408 Symfony\Component\Form\FormBuilder->create( ) ../FormBuilder.php:256
284 1.9558 43972456 Symfony\Component\Form\FormFactory->createNamedBuilder( ) ../FormBuilder.php:118
285 1.9559 43972456 Symfony\Component\Form\ResolvedFormType->createBuilder( ) ../FormFactory.php:87
286 1.9559 43972456 Symfony\Component\OptionsResolver\OptionsResolver->resolve( ) ../ResolvedFormType.php:116
287 1.9561 43981576 Symfony\Component\OptionsResolver\Options->all( ) ../OptionsResolver.php:240
288 1.9561 43984640 Symfony\Component\OptionsResolver\Options->resolve( ) ../Options.php:255
289 1.9561 43984688 Symfony\Component\OptionsResolver\LazyOption->evaluate( ) ../Options.php:399
290 1.9562 43985024 Closure->__invoke( ) ../LazyOption.php:67
291 1.9562 43985056 Symfony\Component\Form\Extension\Core\Type\FormType->Symfony\Component\Form\Extension\Core\Type\{closure}( ) ../LazyOption.php:67
292 1.9562 43985104 Symfony\Component\OptionsResolver\Options->offsetGet( ) ../LazyOption.php:181
293 1.9562 43985104 Symfony\Component\OptionsResolver\Options->get( ) ../Options.php:290
294 1.9562 43985104 Symfony\Component\OptionsResolver\Options->resolve( ) ../Options.php:184
295 1.9562 43985152 Symfony\Component\OptionsResolver\LazyOption->evaluate( ) ../Options.php:399
296 1.9562 43985488 Closure->__invoke( ) ../LazyOption.php:67
297 1.9562 43985520 Symfony\Component\Form\Extension\Core\Type\DateTimeType->Symfony\Component\Form\Extension\Core\Type\{closure}( ) ../LazyOption.php:67
298 1.9562 43985568 Symfony\Component\OptionsResolver\Options->offsetGet( ) ../LazyOption.php:195
299 1.9562 43985568 Symfony\Component\OptionsResolver\Options->get( ) ../Options.php:290
´´´
In favor of something else ?
The documentation mentions that the renderFormView
returns a 412 Precondition Failed
error if the form validation fails. The only thing that is similar to that method is renderForm
and it doesn't seem to set any status code.
422 Unprocessable Entity
be more appropriate? See Section 11.2 for a more descriptive argument.Addendum: in terms of Backbone.js, any 4xx error will trigger the error handlers, so it's really more of a conceptual point.
Is it possible to bind a form to an xml string instead of a request ?
More generally, is it possible to restore an entity that has been serialized in a database (says, as a XML string using form_serializer).
Something like
$form->submit($entitySerializedAsXml);
Thanks in advance
Hello,
I'm trying to use your bundle for our application REST API, and I'm serializing my objects to json format.
I need to keep parameter types when serializing, so that null values will be nulls after serialization, and integers remain integers. But I found that for some reason you convert all the json values to strings when calling getClientData() method in serializeForm(). If I change this to getNormData() - everything works just fine.
The question is - was that done intentionally? If yes, then why?
The output of renderForm
is currently escaped. Is there any way to return a unescaped JSON string like FOSRest?
Data passed in getType($type, $recursive = false)
$type
is passed as array
Array
(
[name] => string
[params] => Array
(
)
)
isset($this->typeMap[$type]
isset($this->typeMap[$type['name']]
Allow to disable default xml or json encoders, allow to add new encoders using a DIC tag.
This includes:
This causes json_encode to render it as object instead of an array.
In CollectionTypeExtension.php, the mockup child form that is created and inserted into the "serialize_collection_form" attribute of Collections is not created with the "options" option passed to the collection.
This is a problem when the child form requires a particular option, or changes its behavior based on a particular option. I modified line 26 so that 24-27 read
$builder->setAttribute(
'serialize_collection_form',
$builder->getFormFactory()->create($options['type'], null, $options['options']) // CHANGED, added "options"
);
add missing travis configuration
When CSRF protection is enabled funky form validation errors appear
When serializing a DateTime
object without the single_text
form option, the serialized response is empty:
"{"name":"sample","created_at":{"date":{"year":"","month":"","day":""},"time":{"hour":"","minute":""}}}"
Same object with single_text
:
"{"name":"sample","created_at":"2012-07-20T15:49:59Z"}"
Allow every form to define link relations which are rendered.
JSON:
"links": {}
XML:
<atom:link .../>
There should be a "shortcut" to serialize collections of entities using one form type.
I just installed the bundle (dev-master)
php composer.phar require simplethings/form-serializer-bundle dev-master
and added the bundle to AppKernel.php
new SimpleThings\FormSerializerBundle\SimpleThingsFormSerializerBundle(),
Then submit buttons on my forms disappear everywhere on my symfony2 app.
Any idea on what is happening ?
Symfony2 version: 2.6.4
Add a method to Helper and Controller for getting the FormSerializer from the Container.
would you be interested in adding an example to https://github.com/gimler/symfony-rest-edition ?
There should be an API to generate form builders from Doctrine Metadata.
When using Backbone.js, a common practice is to return a new model
representation after it is processed by the update action (usually a PUT
request). This is useful to update the client-side model with server-side generated data like updatedAt
fields or other domain logic data.
However, Backbone.js does not work well with differential updates when saving models (PATCH
support is funky) - it always sends the complete model object back to the server. Because of the way this is handled, any update action needs to return a complete form serialized back to the client after a successful save - and this means I need the updatedAt
field on that form.
The problem is that the unserializeForm will now let the Form component set that value on the object, as if it was manually set. This breaks LifeCycleEvents that depend on this check to determine wether a new value should be set or not (see the TimestampableListener from Gedmo).
Any ideas or workarounds to solve this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.