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 7960411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:44:50+00:00 2026-06-04T04:44:50+00:00

I’ve just imported the FOSUserBundle for the first time into a symfony2 project and

  • 0

I’ve just imported the FOSUserBundle for the first time into a symfony2 project and I’ve noticed an issue when extending the user entity. I added created_at and updated_at fields with prePersist and preUpdate lifecycle callbacks but these methods are not being read.

If I put setters for these fields in the constructor then the fields are populated (but obviously this does not work correctly with updated_at). The other fields I have added have worked as expected.

Do you need to extend the UserListener in some way to allow the lifecycle events to work correctly?

Please find my code below, any help or advice would be greatly appreciated.

UserEntity:

namespace Acme\UserExtensionBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Acme\UserExtensionBundle\Entity\User
 *
 * @ORM\Table(name="acme_user")
 * @ORM\Entity()
 * @ORM\HasLifecycleCallbacks()
 */
class User extends BaseUser{

  /**
   * @var integer $id
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;

  /**
   * @var datetime $created_at
   * @ORM\Column(name="created_at", type="datetime")
   */
  protected $created_at;

  /**
   * @var datetime $updated_at
   * @ORM\Column(name="updated_at", type="datetime")
   */
  protected $updated_at;

  ...

  public function __construct() {
    parent::__construct();
    $this->created_at = new \DateTime;
    $this->updated_at = new \DateTime;
  }

  /*
   * @ORM\preUpdate
   */
  public function setUpdatedTimestamp(){
    $this->updated_at = new \DateTime();
  }

  ...
  • 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-06-04T04:44:51+00:00Added an answer on June 4, 2026 at 4:44 am

    After a quick look I can only spot a little error with the case of the Annotations name.

    It should be

    @ORM\PreUpdate
    

    instead of

    @ORM\preUpdate
    

    which IMHO should lead to an error when executed.

    Anyway I would suggest you to use the DoctrineExtensionsBundle described in http://symfony.com/doc/current/cookbook/doctrine/common_extensions.html .

    It comes with a Timestampable (and many more useful) behaviours so you do not need to code this on your own (reinventing the wheel).

    I’m using it together with FOSUserBundle and it works fine. This is how my definition in the User Entity looks like:

     /**
     * @var \DateTime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    protected $created;
    
    /**
     * @var \DateTime  $updated
     *
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(type="datetime")
     */
    protected $updated;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker

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.