Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two strange things going on here which I think break your code.</p> <ol> <li><p>You run the <code>bind()</code> method twice which might be resetting your values on the object.</p></li> <li><p>I don't think that the <code>getObject()</code> method returns the object by reference.</p></li> </ol> <p>So when you run:</p> <pre><code> $form-&gt;getObject()-&gt;setX($val); $form-&gt;save(); </code></pre> <p>then you update the field of the object returned by the form, but then save the original object which is still bound to the form.</p> <p>Try doing something like this:</p> <pre><code> $myObject = $form-&gt;updateObject()-&gt;getObject(); $myObject-&gt;setX($value); $myObject-&gt;save(); </code></pre> <p>The <code>updateObject()</code> is important if you use the form to edit an existing object, not to create a new one. Without this you will get the old values of the object.</p> <p>If you want to run it in a loop you can loop only the setting and saving part. So you would have something like this in your <code>processCreateForm</code>:</p> <pre><code>protected function processCreateForm(sfWebRequest $request, sfForm $form) { $form-&gt;bind($request-&gt;getParameter($form-&gt;getName()), $request-&gt;getFiles($form-&gt;getName())); if ($form-&gt;isValid()) { //You can check the validity of your form at this point. //Create $theatersList ... $myObject = $form-&gt;updateObject(); foreach ($theatersList as $theater) { $myObject-&gt;setTheaterId($theater-&gt;theater_id); $showing = $myObject-&gt;save(); //Do something with $showing } } else { //Print the errors. } } </code></pre> <p>Using this code you can unset the widget for <code>theatre_id</code> in your form as it should not be set by the user and does not have to be part of the form validation.</p> <p><strong>EDIT</strong></p> <p>Some changes to the code:</p> <pre><code>protected function processCreateForm(sfWebRequest $request, sfForm $form) { $form-&gt;bind($request-&gt;getParameter($form-&gt;getName()), $request-&gt;getFiles($form-&gt;getName())); if ($form-&gt;isValid()) { //You can check the validity of your form at this point. //Create $theatersList ... $myObject = $form-&gt;updateObject(); $myObjectVars = $myObject-&gt;toArray(); foreach ($theatersList as $theater) { $myNewObject = new SomeClass(); $myNewObject-&gt;fromArray($myObjectVars); $myNewObject-&gt;setTheaterId($theater-&gt;theater_id); $showing = $myNewObject-&gt;save(); //Do something with $showing $myNewObject-&gt;free(); unset($myNewObject); } } else { //Print the errors. } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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