Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest using Pazis solution, since this is the most simple one. But that would also be a perfect job for a DataTransformer:</p> <pre><code>class MyDataTransformer implements DataTransformerInterface { public function transform($value) { if (null === $value) return; if ($value instanceof \DateTime) return array( 'date' =&gt; $value-&gt;format('d.m.Y'), 'time' =&gt; $value-&gt;format('H:i:s') ); return null; } public function reverseTransform($value) { if (null === $value) return null; if (is_array($value) &amp;&amp; array_key_exists('date', $value) &amp;&amp; array_key_exists('time', $value)) return new \DateTime($value['date'] . ' ' . $value['time']); return null; } } </code></pre> <p>This has the drawback, that you'd need to map every single value in your entity with this transformer, what - for sure - you don't want to. But with small form-tricks, this can be avoided. Therefore you add a subform to your form, which includes a date and a time field and the added Transformer. You'll need to map ("property_path"-option) your DateTime object to this subform or just name it "correctly", so the form framework can map it by name.</p> <pre><code>public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add( $builder-&gt;create('datetime', 'form') -&gt;add('date', 'date', $optionsForDate) -&gt;add('time', 'time', $optionsForTime) -&gt;addViewTransformer(new MyDataTransformer()) ); } </code></pre> <p>The code may not be perfectly running, but i hope the idea behind splitting one entity property into two (or more) form fields is clear.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload