Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:37:33+00:00 2026-05-27T02:37:33+00:00

I am trying to get a Date type field from the entity and I

  • 0

I am trying to get a Date type field from the entity and I encounter the following error:

An exception has been thrown during the rendering of a template (“Warning: strtr()
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.

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.

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.

Here is the basic code in my Controller:

    public function addQuestionAction(Request $request){
    $question = new Question();
    $form = $this->createForm(new QuestionType(), $question);

    return $this->render('LaPorchettaWebBundle:Default:add_question.html.twig', array(
        'form'   => $form->createView(),
    ));
}

Here is the TWIG view:

{% extends "LaPorchettaWebBundle:Default:test.html.twig" %}
{% block pageTitle %}LaPorchetta Create A Question{% endblock %}
{% block content %}
<div id="outer">
<form name="petEntry" action="" method="post" enctype="multipart/form-data" >

  {{ form_errors(form) }}

    <div class="left">
      {{ form_label(form.survey) }}
    </div>
    <div class="right">
      {{ form_widget(form.survey) }}
      {{ form_errors(form.survey) }}
    </div>

    <div class="left">
      {{ form_label(form.section) }}
    </div>
    <div class="right">
      {{ form_widget(form.section) }}
      {{ form_errors(form.section) }}
    </div>

    <div class="left">
      {{ form_label(form.sub_section) }}
    </div>
    <div class="right">
      {{ form_widget(form.sub_section) }}
      {{ form_errors(form.sub_section) }}
    </div>

    <div class="left">
      {{ form_label(form.description) }}
    </div>
    <div class="right">
      {{ form_widget(form.description) }}
      {{ form_errors(form.description) }}
    </div>

    <div class="left">
      {{ form_label(form.points) }}
    </div>
    <div class="right">
      {{ form_widget(form.points) }}
      {{ form_errors(form.points) }}
    </div>
  <div id="inputs">
      <input type="button" id="btnCancel" name="cancel" value="Cancel"   
 onclick="window.location = '' " />
      <input id="update" type="submit" value="submit" />
  </div>
</div>
</form>
</div>
{% endblock %}

I have the following entities:

<?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->question    = new ArrayCollection();
    $this->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->id;
}    

/**
* @ORM\prePersist
*/
public function setSurveyDate()
{
    $this->survey_date = new \DateTime();
}

/**
 * Get survey_date
 *
 * @return date 
 */
public function getSurveyDate()
{
    return $this->survey_date;
}

/**
 * Add question
 *
 * @param LaPorchetta\WebBundle\Entity\Question $question
 */
public function addQuestion(\LaPorchetta\WebBundle\Entity\Question $question)
{
    $this->question[] = $question;
}

/**
 * Get question
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getQuestion()
{
    return $this->question;
}

/**
 * Set store
 *
 * @param LaPorchetta\WebBundle\Entity\Store $store
 */
public function setStore(\LaPorchetta\WebBundle\Entity\Store $store)
{
    $this->store = $store;
}

/**
 * Get store
 *
 * @return LaPorchetta\WebBundle\Entity\Store 
 */
public function getStore()
{
    return $this->store;
}

/**
 * Get action_item
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getActionItem()
{
    return $this->action_item;
}

/**
 * Set action_item
 *
 * @param LaPorchetta\WebBundle\Entity\Question $actionItem
 */
public function setActionItem(\LaPorchetta\WebBundle\Entity\Question $actionItem)
{
    $this->action_item = $actionItem;
}
}

Entity Type -> Questions

<?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->id;
}

/**
 * Set section
 *
 * @param string $section
 */
public function setSection($section)
{
    $this->section = $section;
}

/**
 * Get section
 *
 * @return string 
 */
public function getSection()
{
    return $this->section;
}

/**
 * Set sub_section
 *
 * @param string $subSection
 */
public function setSubSection($subSection)
{
    $this->sub_section = $subSection;
}

/**
 * Get sub_section
 *
 * @return string 
 */
public function getSubSection()
{
    return $this->sub_section;
}

/**
 * Set description
 *
 * @param string $description
 */
public function setDescription($description)
{
    $this->description = $description;
}

/**
 * Get description
 *
 * @return string 
 */
public function getDescription()
{
    return $this->description;
}

/**
 * Set survey
 *
 * @param LaPorchetta\WebBundle\Entity\Survey $survey
 */
public function setSurvey(\LaPorchetta\WebBundle\Entity\Survey $survey)
{
    $this->survey = $survey;
}

/**
 * Get survey
 *
 * @return LaPorchetta\WebBundle\Entity\Survey 
 */
public function getSurvey()
{
    return $this->survey;
}

/**
 * Set points
 *
 * @param integer $points
 */
public function setPoints($points)
{
    $this->points = $points;
}

/**
 * Get points
 *
 * @return integer 
 */
public function getPoints()
{
    return $this->points;
}
public function __construct()
{
    $this->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->action_item[] = $actionItem;
}

/**
 * Get action_item
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getActionItem()
{
    return $this->action_item;
}

/**
 * Set action_item
 *
 * @param LaPorchetta\WebBundle\Entity\Survey $actionItem
 */
public function setActionItem(\LaPorchetta\WebBundle\Entity\Survey $actionItem)
{
    $this->action_item = $actionItem;
}
}

I have the following QuestionType:

<?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
        ->add('survey', 'entity', array(
                                'class'=>'LaPorchettaWebBundle:Survey',
                                'property'=>'survey_date',
                                'multiple' => true,
                                'required'  => true,
                                'query_builder' => function(EntityRepository $er) {
                                    return  
$er->createQueryBuilder('s')->orderBy('s.survey_date', 'ASC');
                                }))
        ->add('section', 'text')
        ->add('sub_section', 'text')
        ->add('description', 'text')
        ->add('points', 'integer');
}
public function getName()
{
    return 'LaPorchetta_WebBundle_QuestionType';
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:37:34+00:00Added an answer on May 27, 2026 at 2:37 am

    Although not the most convenient way to achieve the desired results, I ended up constructing a form inside the Controller action and when it came to addressing the date field, I used it like so:

    $surveys = $item_repo->findAll();
        foreach($surveys as $survey){
            array_push($dates, $survey->getSurveyDate()->format('d/m/Y') );
        }
        $question = array();
        $form = $this->createFormBuilder( $question )
            ->add('survey', 'choice', array(
                                    'choices' => $dates ))   
            ->add('section', 'text', array('required' => true, 'trim' => true))
            ->add('sub_section', 'text', array('required' => true, 'trim' => true))
            ->add('description', 'text', array('required' => true, 'trim' => true))
            ->add('points', 'integer', array('required' => true, 'trim' => true))
            ->getForm();
    

    In specifying the formatting of the Datetime object, like so (->format(‘d/m/Y’) ), TWIG was able to process the data without any errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to get date from my implementation of jquery date picker, add
I am trying to get the offset hours from UTC, given a summer date.
I am trying to get RTF data out of a image date field in
With ruby I'm trying to get format a date as such: 2009-10-01 Where I
For example, I am trying to get a min date, a max date, and
I am trying to get an array of a date plus the next 13
I am trying to get a attribute of a date picker to pull the
I'm trying to get the unix time for date strings that are formatted like
I'm trying to get the week range using Sunday as the start date, and
I am trying to get the program to call up the current date, add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.