Question

I am using ZF 1.11, PHP 5.3, Windows and the most recent version of zfdatagrid.

I use

$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));

to display an attribute "birthday" as dd-MM-yyyy. When I click on the Edit button (CRUD enabled), the value of this attribute is being displayed as 'yyyy-MM-dd'. When the user clicks the save button, he gets an error message (Please, enter date as dd-MM-yyyy).

How can I tell the $form to display the value as dd-MM-yyyy instead of yyyy-MM-dd?

Était-ce utile?

La solution 2

thanks, but that doesn't solve the problem. Actually, what I did now is to add an event listener for the crud.form_built event. The method called in this event simply creates a new Zend_Validate_Date object and assigns this validator to the corresponding zfdatagrid element.

This is a hack indeed, but it works. Actually, zfdatagrid doesn't really work with PostgreSQL and the manual is incorrent in many places.

Autres conseils

looking at the docks I think your code maybe slighty incorrect:

$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));

Maybe:

$grid->updateColumn('birthday', array('format'=> 'date',array('date_format' => 'dd-MM-yyyy')));

looks like you had an extra array() at date.

reference:

Date ZFDatagrid will for a key in Zend_Registry with the name Zend_Locale and use it. You can also pass as argument a instance of Zend_Locale or an array with the following options

  • locale
  • date_format
  • type

$grid->updateColumn('field',array('format'=>'date'));

!Warning maybe bad English!

for i.e. "localized" values in forms i do something like this..

after passing form to the grid $grid->setForm($myform);

but before the call of $grid->deploy();

i get the form element and set the value manually like the following

$Form=$grid->getForm(1); 

$dateVal = $Form->getElement('birthday')->getValue();

if(Zend_Date::isDate($dateVal,'yyyy-MM-dd', 'en'))   
   $dateObject = new Zend_Date($dateVal);

$Form->getElement('birthday')
     ->setValue($dateObject->toString('dd.MM.yyyy'))
     ->setValidators(array(new Zend_Validate_Date('dd.MM.yyyy')))
     ;

then register a zfdatagrid event trigger "crud.before_update"

$grid->listenEvent('crud.before_update', array($this, '_updateCallback')

that calls a function from this controller _updateCallback() with something custom like this

public function _updateCallback(Bvb_Grid_Event $e) 
{       
   $n = $e->getParam('newValues');
   list($d,$m,$y) = explode('.', $n['birthday']);       
   $sqldate = $y.'-'.$m.'-'.$d;     
   $n['birthday'] = $sqldate;

   $e->setParam('newValues', $n);
}

or just use Zend Date like before to refactor date to ensure that the datevalue we want to save, is in a sql valid US date format..

hope this will help.. z.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top