Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 An exception has been thrown during the rendering of a template strtr() expects parameter 1 to be string, object given
    primarykey
    data
    text
    <p>I am trying to get a Date type field from the entity and I encounter the following error:</p> <blockquote> <p>An exception has been thrown during the rendering of a template ("Warning: strtr()<br> expects parameter 1 to be string, object given in /var/www/feedyourmind_symfony/vendor /symfony/src/Symfony/Component/Translation/IdentityTranslator.php line 62") in form_div_layout.html.twig at line 37.</p> </blockquote> <p>I am fairly new to Symfony2 and can not seem to figure out why I would be getting this error. Perhaps there is something wrong with my Entities? I do not know and I would really like some assistance if possible.</p> <p>Although the error points to an issue with the rendering of a template, I feel that the real error lies with the Entity and the date field not correctly functioning.</p> <p>Here is the basic code in my Controller:</p> <pre><code> public function addQuestionAction(Request $request){ $question = new Question(); $form = $this-&gt;createForm(new QuestionType(), $question); return $this-&gt;render('LaPorchettaWebBundle:Default:add_question.html.twig', array( 'form' =&gt; $form-&gt;createView(), )); } </code></pre> <p>Here is the TWIG view:</p> <pre><code>{% extends "LaPorchettaWebBundle:Default:test.html.twig" %} {% block pageTitle %}LaPorchetta Create A Question{% endblock %} {% block content %} &lt;div id="outer"&gt; &lt;form name="petEntry" action="" method="post" enctype="multipart/form-data" &gt; {{ form_errors(form) }} &lt;div class="left"&gt; {{ form_label(form.survey) }} &lt;/div&gt; &lt;div class="right"&gt; {{ form_widget(form.survey) }} {{ form_errors(form.survey) }} &lt;/div&gt; &lt;div class="left"&gt; {{ form_label(form.section) }} &lt;/div&gt; &lt;div class="right"&gt; {{ form_widget(form.section) }} {{ form_errors(form.section) }} &lt;/div&gt; &lt;div class="left"&gt; {{ form_label(form.sub_section) }} &lt;/div&gt; &lt;div class="right"&gt; {{ form_widget(form.sub_section) }} {{ form_errors(form.sub_section) }} &lt;/div&gt; &lt;div class="left"&gt; {{ form_label(form.description) }} &lt;/div&gt; &lt;div class="right"&gt; {{ form_widget(form.description) }} {{ form_errors(form.description) }} &lt;/div&gt; &lt;div class="left"&gt; {{ form_label(form.points) }} &lt;/div&gt; &lt;div class="right"&gt; {{ form_widget(form.points) }} {{ form_errors(form.points) }} &lt;/div&gt; &lt;div id="inputs"&gt; &lt;input type="button" id="btnCancel" name="cancel" value="Cancel" onclick="window.location = '' " /&gt; &lt;input id="update" type="submit" value="submit" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; {% endblock %} </code></pre> <p>I have the following entities:</p> <pre><code>&lt;?php namespace LaPorchetta\WebBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity(repositoryClass="LaPorchetta\WebBundle\Repository\SurveyRepository") * @ORM\HasLifecycleCallbacks() * @ORM\Table(name="Surveys") */ class Survey { public function __construct() { $this-&gt;question = new ArrayCollection(); $this-&gt;store = new ArrayCollection(); } /** * @ORM\Id @ORM\Column(type="integer") * @ORM\GeneratedValue */ protected $id; /** * @ORM\Column(type="date") */ protected $survey_date; /** * @ORM\OneToMany(targetEntity="Question", mappedBy="survey") */ protected $question = null; /** * @ORM\OneToOne(targetEntity="Store", inversedBy="survey") */ protected $store = null; /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * @ORM\prePersist */ public function setSurveyDate() { $this-&gt;survey_date = new \DateTime(); } /** * Get survey_date * * @return date */ public function getSurveyDate() { return $this-&gt;survey_date; } /** * Add question * * @param LaPorchetta\WebBundle\Entity\Question $question */ public function addQuestion(\LaPorchetta\WebBundle\Entity\Question $question) { $this-&gt;question[] = $question; } /** * Get question * * @return Doctrine\Common\Collections\Collection */ public function getQuestion() { return $this-&gt;question; } /** * Set store * * @param LaPorchetta\WebBundle\Entity\Store $store */ public function setStore(\LaPorchetta\WebBundle\Entity\Store $store) { $this-&gt;store = $store; } /** * Get store * * @return LaPorchetta\WebBundle\Entity\Store */ public function getStore() { return $this-&gt;store; } /** * Get action_item * * @return Doctrine\Common\Collections\Collection */ public function getActionItem() { return $this-&gt;action_item; } /** * Set action_item * * @param LaPorchetta\WebBundle\Entity\Question $actionItem */ public function setActionItem(\LaPorchetta\WebBundle\Entity\Question $actionItem) { $this-&gt;action_item = $actionItem; } } </code></pre> <p>Entity Type -> Questions</p> <pre><code>&lt;?php namespace LaPorchetta\WebBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity(repositoryClass="LaPorchetta\WebBundle\Repository\QuestionRepository") * @ORM\Table(name="Questions") */ class Question { /** * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ protected $id; /** * @ORM\ManyToOne(targetEntity="Survey", inversedBy="question") */ protected $survey; /** * @ORM\Column(type="string") */ protected $section; /** * @ORM\Column(type="string") */ protected $sub_section; /** * @ORM\Column(type="string") */ protected $description; /** * @ORM\Column(type="integer") */ protected $points; /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set section * * @param string $section */ public function setSection($section) { $this-&gt;section = $section; } /** * Get section * * @return string */ public function getSection() { return $this-&gt;section; } /** * Set sub_section * * @param string $subSection */ public function setSubSection($subSection) { $this-&gt;sub_section = $subSection; } /** * Get sub_section * * @return string */ public function getSubSection() { return $this-&gt;sub_section; } /** * Set description * * @param string $description */ public function setDescription($description) { $this-&gt;description = $description; } /** * Get description * * @return string */ public function getDescription() { return $this-&gt;description; } /** * Set survey * * @param LaPorchetta\WebBundle\Entity\Survey $survey */ public function setSurvey(\LaPorchetta\WebBundle\Entity\Survey $survey) { $this-&gt;survey = $survey; } /** * Get survey * * @return LaPorchetta\WebBundle\Entity\Survey */ public function getSurvey() { return $this-&gt;survey; } /** * Set points * * @param integer $points */ public function setPoints($points) { $this-&gt;points = $points; } /** * Get points * * @return integer */ public function getPoints() { return $this-&gt;points; } public function __construct() { $this-&gt;action_item = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add action_item * * @param LaPorchetta\WebBundle\Entity\Survey $actionItem */ public function addSurvey(\LaPorchetta\WebBundle\Entity\Survey $actionItem) { $this-&gt;action_item[] = $actionItem; } /** * Get action_item * * @return Doctrine\Common\Collections\Collection */ public function getActionItem() { return $this-&gt;action_item; } /** * Set action_item * * @param LaPorchetta\WebBundle\Entity\Survey $actionItem */ public function setActionItem(\LaPorchetta\WebBundle\Entity\Survey $actionItem) { $this-&gt;action_item = $actionItem; } } </code></pre> <p>I have the following QuestionType:</p> <pre><code>&lt;?php namespace LaPorchetta\WebBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Doctrine\ORM\EntityRepository; class QuestionType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('survey', 'entity', array( 'class'=&gt;'LaPorchettaWebBundle:Survey', 'property'=&gt;'survey_date', 'multiple' =&gt; true, 'required' =&gt; true, 'query_builder' =&gt; function(EntityRepository $er) { return $er-&gt;createQueryBuilder('s')-&gt;orderBy('s.survey_date', 'ASC'); })) -&gt;add('section', 'text') -&gt;add('sub_section', 'text') -&gt;add('description', 'text') -&gt;add('points', 'integer'); } public function getName() { return 'LaPorchetta_WebBundle_QuestionType'; } } </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