Formularios
Versión 5 (Guillermo Zdanowicz, 22/03/2012 01:41)
| 1 | 1 | Guillermo Zdanowicz | h1. Formularios |
|---|---|---|---|
| 2 | 1 | Guillermo Zdanowicz | |
| 3 | 1 | Guillermo Zdanowicz | |
| 4 | 2 | Guillermo Zdanowicz | ------------------------------------------------------------------------------------------ |
| 5 | 1 | Guillermo Zdanowicz | Ejemplo de sentencias en el form |
| 6 | 1 | Guillermo Zdanowicz | |
| 7 | 2 | Guillermo Zdanowicz | ------------------------------------------------------------------------------------------ |
| 8 | 1 | Guillermo Zdanowicz | class AreasForm extends BaseAreasForm |
| 9 | 1 | Guillermo Zdanowicz | { |
| 10 | 1 | Guillermo Zdanowicz | public function configure() |
| 11 | 1 | Guillermo Zdanowicz | { |
| 12 | 1 | Guillermo Zdanowicz | |
| 13 | 1 | Guillermo Zdanowicz | parent::setup(); |
| 14 | 1 | Guillermo Zdanowicz | |
| 15 | 1 | Guillermo Zdanowicz | unset($this['created_at'],$this['updated_at']); // quita estos campos para que no se visualicen en el formulario |
| 16 | 1 | Guillermo Zdanowicz | |
| 17 | 1 | Guillermo Zdanowicz | //formato de los campos fecha |
| 18 | 1 | Guillermo Zdanowicz | b$format = '%day%/%month%/%year%'; |
| 19 | 1 | Guillermo Zdanowicz | //define el rango de campo fecha |
| 20 | 1 | Guillermo Zdanowicz | $range = range(date('Y')-90, date('Y')-15); |
| 21 | 1 | Guillermo Zdanowicz | $years = array_combine($range,$range); |
| 22 | 1 | Guillermo Zdanowicz | // setea la condifuracion de campo fecha en el campo del formulario |
| 23 | 1 | Guillermo Zdanowicz | $this->widgetSchema['fechanac'] = new sfWidgetFormDate(array('years' => $years, 'format' => $format )); |
| 24 | 1 | Guillermo Zdanowicz | } |
| 25 | 1 | Guillermo Zdanowicz | |
| 26 | 1 | Guillermo Zdanowicz | } |
| 27 | 2 | Guillermo Zdanowicz | |
| 28 | 2 | Guillermo Zdanowicz | |
| 29 | 2 | Guillermo Zdanowicz | ------------------------------------------------------------------------------------------ |
| 30 | 3 | Guillermo Zdanowicz | //setear un valor por defecto en un campo determinado |
| 31 | 3 | Guillermo Zdanowicz | $this->widgetSchema['my_field']->setDefault(my_default_value); |
| 32 | 3 | Guillermo Zdanowicz | //ocultar un campo |
| 33 | 3 | Guillermo Zdanowicz | $this->widgetSchema['idCreador']->setOption('type', 'hidden'); |
| 34 | 3 | Guillermo Zdanowicz | // cambiar el nombre de una etiqueta |
| 35 | 3 | Guillermo Zdanowicz | $this->widgetSchema['idCreador']->setLabel('Creador'); |
| 36 | 4 | Guillermo Zdanowicz | |
| 37 | 4 | Guillermo Zdanowicz | |
| 38 | 4 | Guillermo Zdanowicz | |
| 39 | 4 | Guillermo Zdanowicz | |
| 40 | 4 | Guillermo Zdanowicz | |
| 41 | 4 | Guillermo Zdanowicz | ------------------------------------------------------------------------------------------ |
| 42 | 4 | Guillermo Zdanowicz | Para personalizar listado |
| 43 | 4 | Guillermo Zdanowicz | |
| 44 | 4 | Guillermo Zdanowicz | |
| 45 | 4 | Guillermo Zdanowicz | $maxLimit = 10; |
| 46 | 4 | Guillermo Zdanowicz | $this->pager = new sfDoctrinePager('expedientes', $maxLimit); |
| 47 | 4 | Guillermo Zdanowicz | |
| 48 | 4 | Guillermo Zdanowicz | $q = Doctrine_Query::create() |
| 49 | 4 | Guillermo Zdanowicz | ->from('expedientes e') |
| 50 | 4 | Guillermo Zdanowicz | ->where('e.finalizado = 0'); |
| 51 | 4 | Guillermo Zdanowicz | |
| 52 | 4 | Guillermo Zdanowicz | $this->pager->setQuery($q); |
| 53 | 4 | Guillermo Zdanowicz | $this->pager->setPage($request->getParameter('page', 1)); |
| 54 | 4 | Guillermo Zdanowicz | $this->pager->init(); |
| 55 | 5 | Guillermo Zdanowicz | |
| 56 | 5 | Guillermo Zdanowicz | ----------------------------------------------------- |
| 57 | 5 | Guillermo Zdanowicz | OTRO EJEMPLO |
| 58 | 5 | Guillermo Zdanowicz | ----------------------------------------------------- |
| 59 | 5 | Guillermo Zdanowicz | |
| 60 | 5 | Guillermo Zdanowicz | public function executeList(sfWebRequest $request) |
| 61 | 5 | Guillermo Zdanowicz | { |
| 62 | 5 | Guillermo Zdanowicz | $maxLimit = 10; |
| 63 | 5 | Guillermo Zdanowicz | $this->pager = new sfDoctrinePager('netNews', $maxLimit); |
| 64 | 5 | Guillermo Zdanowicz | |
| 65 | 5 | Guillermo Zdanowicz | |
| 66 | 5 | Guillermo Zdanowicz | //$this->pager->setQuery(Doctrine::getTable('netNews')->createQuery('a')); |
| 67 | 5 | Guillermo Zdanowicz | |
| 68 | 5 | Guillermo Zdanowicz | $q = Doctrine_Query::create() |
| 69 | 5 | Guillermo Zdanowicz | ->from('netNews n') |
| 70 | 5 | Guillermo Zdanowicz | ->where('n.publicada = 1'); |
| 71 | 5 | Guillermo Zdanowicz | |
| 72 | 5 | Guillermo Zdanowicz | $this->pager->setQuery($q); |
| 73 | 5 | Guillermo Zdanowicz | $this->pager->setPage($request->getParameter('page', 1)); |
| 74 | 5 | Guillermo Zdanowicz | $this->pager->init(); |
| 75 | 5 | Guillermo Zdanowicz | } |