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

    Digg Digg

    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

    12 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.

    Leave a Reply


    Subscribe to Levelx

    Popular Posts

    • Create a jigsaw puzzle in adobe illustrator
    • At The Heart of The Image! – Nikon D5000 Review
    • Calibrating HTC Desire Battery
    • Famous Salvador Dali Paintings
    • Taking Screenshots on HTC Desire
    • Typography Tips – With Amazing Examples
    • Home Decoration and Interior Design 2011
    • Funny Road Signs (Part II)
    • Nokia Touch and Type X3-02 and C3-01: Review and Comparison
    • 3D Building Exterior Render – Design Workflow

    Recent Comments

    • Loading...

    Top Posts

    • FORMULA 1 - 2009 Season. (28)
    • Fixing IE7 dropping PHP Sessions (25)
    • M2N32 SLI-DLX WFI && RzR DeathADDER - - BURNT ! ! (17)
    • HTC Desire - Benchmark (17)
    • Home Decoration and Interior Design 2011 (17)
    • From Sand To Silicon: How A Intel CPU Is Built (16)
    • Windows 7 Theme - VEER II (16)
    • HTC Desire 2.10.405.2 OTA Update (16)
    • REQ: Stalker [ 1979 ] OST. (15)
    • Meet your DESIRE | HTC Desire Reviewed (15)

    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