Note that there are some explanatory texts on larger screens.

plurals
  1. POsymfony form : how to show the parameter in the view, "variable does not exist..."
    primarykey
    data
    text
    <p>I'm using a form with 2 classes ("<code>ArticleType</code>" and "<code>ArticleHandler</code>") for my class Article. </p> <p>I would like to send the id of the article I've just created, but I can't manage to show this id parameter in the view :</p> <p>In the controller, I send my article's id :</p> <pre><code>$handler = new ArticleHandler($form, $request, $em); if ($handler-&gt;process()){ return $this-&gt;redirect($this-&gt;generateUrl('myproject_show', array('id' =&gt; $article-&gt;getId())) ); } </code></pre> <p>and in the view, I've got an error with :</p> <pre><code>{% block body %} &lt;p&gt;the id :&lt;/p&gt; {{ id }} {% endblock %} </code></pre> <p>or <code>entity.id</code> (as in the CRUD) :</p> <blockquote> <p>Variable "id" does not exist...<br> Variable "entity.id" does not exist...</p> </blockquote> <p>Do you know how to fix this?</p> <p>Thanks</p> <hr> <p>EDIT : here's my method : </p> <pre><code>public function addAction() { $article = new Article(); $form = $this-&gt;createForm(new ArticleType(), $article); $request = $this-&gt;getRequest(); $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); $handler = new ArticleHandler($form, $request, $em); if ($handler-&gt;process()){ return $this-&gt;redirect($this-&gt;generateUrl('myproject_show', array('id' =&gt; $article-&gt;getId())) ); } return $this-&gt;render('ProjBlogBundle:Blog:add.html.twig', array( 'form' =&gt; $form-&gt;createView(), )); } </code></pre> <p>and here's the view : </p> <pre><code>{% extends "ProjBlogBundle::layout.html.twig" %} {% block title %} the title - {{ parent() }} {% endblock %} {% block sousbody %} &lt;p&gt;here's the article i've just created :&lt;/p&gt; {{ id }} {% endblock %} </code></pre> <hr> <p>EDIT N°2 :</p> <pre><code>myproject_show: pattern: /show/{id} defaults: { _controller: ProjBlogBundle:Blog:show, id:5 } </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.
 

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