Note that there are some explanatory texts on larger screens.

plurals
  1. POEntities passed to the choice field must be managed
    primarykey
    data
    text
    <p>I create a new object and bind it to a form. The user fills out the form and goes to a preview page. I store the user responses in the session.</p> <p>The problem crops up when I try to reload the object from the session when the user goes back to edit the form. I get the Entities passed to the choice field must be managed error.</p> <p>Anyone have an idea of where i might be going wrong? Heres the code for the controllers.</p> <pre><code>public function previewdealAction(Request $request){ $session = $this-&gt;getRequest()-&gt;getSession(); $coupon = $session-&gt;get('coupon'); $form = $this-&gt;createForm(new CouponType(), $coupon); if ($request-&gt;getMethod() == 'POST') { //bind the posted form values $form-&gt;bindRequest($request); //once a valid form is submitted ... if ($form-&gt;isValid()){ //Proceed to Previewing deal $file = $coupon-&gt;getImage(); $file-&gt;upload(); $session-&gt;set('coupon', $coupon); $repository = $this-&gt;getDoctrine() -&gt;getRepository('FrontendUserBundle:Coupon'); $coupons = $repository-&gt;findAll(); return $this-&gt;render('FrontendHomeBundle:Merchant:dealpreview.html.twig', array('coupon'=&gt;$coupon, 'coupons'=&gt;$coupons)); } } } public function builddealAction(Request $request){ $em = $this-&gt;get('doctrine')-&gt;getEntityManager(); $user = $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser(); //check for a coupon session variable $session = $this-&gt;getRequest()-&gt;getSession(); $coupon = $session-&gt;get('coupon'); //If coupon is not set if($coupon == NULL){ $coupon = new Coupon(); $date = new \DateTime(date("Y-m-d H:i:s")); $coupon-&gt;setStartdate($date); $coupon-&gt;setPosterid($user); $session-&gt;set('coupon', $coupon); } $form = $this-&gt;createForm(new CouponType(), $coupon); return $this-&gt;render('FrontendHomeBundle:Merchant:builddeal.html.twig', array( 'form' =&gt; $form-&gt;createView(), )); } </code></pre> <p>--</p> <pre><code>namespace Frontend\HomeBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class CouponType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder-&gt;add('couponname', 'text'); $builder-&gt;add('description', 'textarea'); $builder-&gt;add('price', 'money', array('currency' =&gt; 'USD')); $builder-&gt;add('originalprice', 'money', array('currency' =&gt; 'USD')); $builder-&gt;add('maxlimit', 'integer'); $builder-&gt;add('maxper', 'integer'); $builder-&gt;add('startdate', 'date', array( 'years' =&gt; array(2011, 2012, 2013, 2014), )); $builder-&gt;add('duration', 'choice', array( 'choices' =&gt; array( '3' =&gt; 3, '7' =&gt; 7, '14' =&gt; 14, '30' =&gt; 30, '60' =&gt; 60, '90' =&gt; 90, ), 'expanded' =&gt; false, 'multiple' =&gt; false, )); $builder-&gt;add('expirationdate', 'choice', array( 'choices' =&gt; array( '30' =&gt; 30, '60' =&gt; 60, '90' =&gt; 90, '180' =&gt; 180, ), 'expanded' =&gt; false, 'multiple' =&gt; false, )); $builder-&gt;add('tip', 'integer'); $builder-&gt;add('salestax', 'choice', array( 'choices' =&gt; array( 'included' =&gt; 'Sales tax is included and will be remitted BY YOU at the appropriate tax jurisdiction', 'exempt' =&gt; 'Sales tax is exempt according to seller\'s tax jurisdiction', 'collected' =&gt; 'Sales tax will be collected BY YOU at time of deal redemption', ), 'expanded' =&gt; true, 'multiple' =&gt; false, )); $builder-&gt;add('signature', 'text'); $builder-&gt;add('city', 'entity', array( 'class' =&gt; 'Frontend\\UserBundle\\Entity\\Cities', 'expanded' =&gt; false, 'multiple' =&gt; false, )); $builder-&gt;add('category', 'entity', array( 'class' =&gt; 'Frontend\\UserBundle\\Entity\\Category', 'expanded' =&gt; false, 'multiple' =&gt; false, )); $builder-&gt;add('address', new AddressType()); $builder-&gt;add('image', new DocumentType()); $builder-&gt;add('maxper', 'choice', array( 'choices' =&gt; array( '1' =&gt; 1, '2' =&gt; 2, '3' =&gt; 3, '4' =&gt; 4, '5' =&gt; 5, '6' =&gt; 6, '7' =&gt; 7, '8' =&gt; 8, '9' =&gt; 9, '10' =&gt; 10, ), 'expanded' =&gt; false, 'multiple' =&gt; false, )); } public function getDefaultOptions(array $options) { return array( 'data_class' =&gt; 'Frontend\UserBundle\Entity\Coupon', ); } public function getName() { return 'user'; } } </code></pre> <p>heres the coupon type class</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.
 

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