sábado, 21 de agosto de 2010

Esconder Campos Timestampables en los Forms de Symfony

Cuando se crea una tabla con el "Comportamiento" Timestampable Doctrine agrega un campo created_at y otro updated_at.
Por ejemplo en el schema.yml tendríamos algo como
Brand:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
code:
type: string(15)
notnull: true
name:
type: string(30)
notnull: true
description:
type: string(255)

Cuando se crea un modulo con el comando generate-module el form de edición tiene los campos created_at y updated_at como campos editables. Esto no debería ser.
symfony doctrine:generate-module backend brand Brand --with-show

Para corregir esto es necesario hacer dos cosas:

1. Agregar el siguiente código en el método configure en el archigo myproyecto/lib/form/doctrine/BrandForm.class.php
public function configure()
{
unset($this->widgetSchema['created_at']);
unset($this->validatorSchema['created_at']);
unset($this->widgetSchema['updated_at']);
unset($this->validatorSchema['updated_at']);
}

2. Editar el archivo myproyecto/apps/backend/modules/brand/templates/_form.php eliminando la creación de los widgets para created_at y updated_at.