levelx.me

  • Home
  • Design
    • 3D
    • Art
    • Freebies
    • Inspiration
    • Interior Design
    • Photography
    • Tutorials
    • Typography
  • Technology
    • Benchmarks
    • How To
    • News
    • Programming
    • Reviews
    • SAP BASIS
  • Lifestyle
    • Do it Yourself
    • Entertainment
    • Quotes
    • Self Improvement
    • Sports
  • Resources
    • Infographics
    • Themes
    • Tools
    • Wallpapers
  • ETC
    • places
    • Uncategorized
  • Android
    • How To
    • News
  • Apple
    • How To
    • News
  • Symfony 1.4 – Doctrine Timestampable Behaviour

    Recently Symfony released their LTS 1.4 branch. Unlike previous versions Symfony 1.4 comes with Doctrine as default ORM.  If you have worked with Doctrine’s you will be familiar with its Timestampable behavior.

    actAs:
      Timestampable: ~

    Timestampable behavior  automatically adds a created_at and updated_at column and automatically set the values when a record is inserted and updated.  I mostly use Symfony Admin Generator to generate Backend. This behavior worked fined till Symfony 1.2, but in Symfony 1.3 / 1.4 for unknown reasons this behavior adds created_at and updated_at fields as required and their value must be filled during creation of new record in admin generator.

    To fix this issue open your formClass located at

    lib/form/doctrine/yourClassForm.Class.php

    replace yourClass with actuall class name :) and add following code in configure function.

    public function configure()
    {
      //Following code will remove Required validators from these fields.
      unset($this->validatorSchema['created_at']);
      unset($this->validatorSchema['updated_at']);
      //following code will remove fields from form
      unset($this->widgetSchema['created_at']);
      unset($this->widgetSchema['updated_at']);
    }

    Hope this help

    You should read

    • Symfony 1.4 – Doctrine and Multiple Database Connections
    • Symfony Admin Generator Calling Actions with Custom Parameters
    • Facebook for Android 1.3 Update
    • Winamp For Android – Available now
    • Facebook For Android V1.4.0 – Groups & Places

    Posted by Faizan on: February 13th, 2010 | Posted in: Programming

    13 Responses to “Symfony 1.4 – Doctrine Timestampable Behaviour”

    rdcklinux on February 13th, 2010 at 1:52 AM

    si ejecutas
    unset($this['created_at'],$this['updated_at']);

    hace exactamente lo mismo y es mas corto de escribir

    rdcklinux on February 13th, 2010 at 1:54 AM

    if you write
    unset($this['created_at'],$this['updated_at']);
    it is the same!!

    rdcklinux on February 13th, 2010 at 1:56 AM

    @rdcklinux
    in symfony 1.4

    Kryptic on February 13th, 2010 at 1:57 AM

    @rdcklinux
    Thanks for update :) but my code is more descriptive

    Jorge on February 17th, 2010 at 11:52 PM

    Y que sucede si lo que se desea es que aparezca el campo, por ejemplo el ID de una persona que es usado como llave primaria.

    Hasta donde he visto Symfony lo oculta automaticamente…
    cómo se debe configurar el Widget para que parezca?

    Muchas gracias por su ayuda.

    Kryptic on February 17th, 2010 at 11:59 PM

    @Jorge
    By admin por defecto de Symfony generados módulo muestra las claves principales. si no se muestran comprobar su archivo generator.yml
    config:
    list:
    display: [id,name,etc]

    Anton on April 25th, 2010 at 8:50 PM

    Hi Stig!
    Why you cant use more plain solution? Just pass “required => false” to these fields validators?

    $this->validatorSchema['created_at']->setOption(‘required’, false);
    $this->validatorSchema['updated_at']->setOption(‘required’, false);

    Samarone Lopes on August 6th, 2010 at 5:57 AM

    Better solution:

    abstract class BaseFormDoctrine extends sfFormDoctrine
    {
    public function setup()
    {
    unset($this->validatorSchema['created_at']);
    unset($this->validatorSchema['updated_at']);
    }
    }

    thanks for idea!

    How to get sfFormExtraPlugin working in Symfony 1.4 using Doctrine | My Rant on October 18th, 2010 at 2:32 AM

    [...] fields created_at and updated_at in that they have to be unset to become magic. Found help here: http://levelx.me/technology/programming/symfony-1-4-doctrine-timestampable-behaviour/ Though the unset lines are better off being added just once to [...]

    Tahsin Hasan on December 5th, 2010 at 1:01 PM

    hello,

    nice posts, .. . see mores on tahSin’s gaRage.

    Erman Taylan on January 19th, 2011 at 3:46 PM

    thanks a lot. that’s that i am looking for

    Tadek Chavez on July 14th, 2011 at 10:54 AM

    I applied this solution directly to BaseFormDoctrine class and that’s what I’d recommend to do.

    I don’t think anyone would want/need their users to set a creation nor an update timestamp manually.

    Tomasz Ducin on February 5th, 2012 at 6:17 PM

    NIce post, but really simple stuff. You can find more information about symfony/doctrine behaviors here: http://symfony-world.blogspot.com/2010/10/symfonydoctrine-behavior-review.html

    Leave a Reply


    Subscribe to Levelx

    Popular Posts

    • Create a jigsaw puzzle in adobe illustrator
    • Nokia 5130 XpressMusic Unboxing & Review
    • Famous Salvador Dali Paintings
    • Kaghan Valley – Pakistan
    • Engine Start Sounds, Ringtones for Motorheads
    • Beauty of Azad Kashmir
    • Canon MP145 All in One Printer/Scanner/Copier
    • Symfony 1.4 – Doctrine and Multiple Database Connections
    • Symfony 1.4 – Doctrine Timestampable Behaviour
    • Enable Numeric Battery Percentage indicator in Ipod Touch

    Recent Comments

    • Loading...

    Top Posts

    • FORMULA 1 - 2009 Season. (28)
    • Fixing IE7 dropping PHP Sessions (25)
    • The Temples of Katas Raj (20)
    • Create a jigsaw puzzle in adobe illustrator (18)
    • M2N32 SLI-DLX WFI && RzR DeathADDER - - BURNT ! ! (17)
    • From Sand To Silicon: How A Intel CPU Is Built (17)
    • Windows 7 Theme - VEER II (17)
    • HTC Desire - Benchmark (17)
    • Calibrating HTC Desire Battery (17)
    • Home Decoration and Interior Design 2011 (17)

    Tags

    1TB android android 2.3 gingerbread android software apple art asus benchmark desire desktop eclair facebook Formula 1 froyo Gaming gingerbread google hacking htc HTC Desire infographic internet ios iPad iphone Islam lahore Lifestyle mobile new year Nexus one Nokia nvidia pakistan photography php psp Review s60 smart phones symbian symfony typography wallpapers web 2.0

    levelx.me is proudly powered by WordPress | Theme Designed by AF8AB