Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating an object in the database from a form
    primarykey
    data
    text
    <p>I have a table with domains and their start dates. I want when I click on a domain, a form for edit(update) to be shown with its fields filled with the current information. I have made this so far:</p> <pre><code>class Domains { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=100) */ protected $main_domain; /** * @ORM\Column(type="date", nullable=true) */ protected $start_date; </code></pre> <p>... with setters and getters for each property.</p> <p>I create a class EditType for building the form:</p> <pre><code>public function buildForm(FormBuilder $builder, array $options) { $builder-&gt;add('start_date', 'date', array('widget' =&gt; 'single_text', 'format' =&gt; 'yyyy-MM-dd')); } </code></pre> <p>with a getName() method and here comes the problem with the EditController:</p> <pre><code>class EditController extends Controller { /** * @Route("/fc/edit/{id}") */ public function editAction($id, Request $request) { $domain = $this-&gt;getDoctrine() -&gt;getRepository('AcmeAbcBundle:Domains') -&gt;find($id); if (!$domain) { throw $this-&gt;createNotFoundException('No domians found'); } $form = $this-&gt;createForm(new EditType(), $domain); if($request-&gt;getMethod() != 'POST') { return $this-&gt;render('AcmeAbcBundle:Edit:form.html.twig', array( 'id'=&gt;$id, 'domain'=&gt;$domain, 'form' =&gt; $form-&gt;createView() )); } if ($request-&gt;getMethod() == 'POST') { $form-&gt;bindRequest($request); print_r($request); if ($form-&gt;isValid()) { $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); $domain = $em-&gt;getRepository('AcmeAbcBundle:Domains'); if (!$domain) { throw $this-&gt;createNotFoundException('There is no such domain'); } $domain-&gt;setStartDate($request-&gt;getStartDate()); $em-&gt;flush(); } return $this-&gt;redirect($this-&gt;generateUrl('homepage')); } </code></pre> <p>I don't have an idea how it should be :( I tried some things but they didn't seem to work. </p> <pre><code>$domain-&gt;setStartDate($request-&gt;getStartDate()); </code></pre> <p>Here it doesn't find the method, if it is $request->start_date it does't find the property ...</p>
    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. 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