Posts Tagged ‘quickie’

quickie: creating symfony delete button

Friday, January 15th, 2010

Many months ago I had asked for help on the symfony forums on how to create a delete button using either the link_to() or button_to() method. I had tried but was always getting validation errors. Today a person asked whether anyone had figured out a solution. It prompted me to do more research into symfony’s core code and found a solution (though the solution wasn’t in the core code).

Original delete text link code:

echo link_to(
	'Delete',
	'state/delete?id='.$form->getObject()->getId(),
	array('method' => 'delete', 'confirm' => 'Are you sure?')
);

New delete BUTTON link code:

echo link_to(
	'<button>Delete</button>',
	'state/delete?id='.$form->getObject()->getId(),
	array('method' => 'delete', 'confirm' => 'Are you sure?')
);

Till Next Time

quickie: setting symfony datetime default

Wednesday, January 6th, 2010

Setting the default value for a symfony form field is one of those tasks so simple that it’s impossible to find out how to do it without a good bit of trial and error.  So without further ado, here is how to set a DateTime field’s default value:

$this->widgetSchema['start_time']->setDefault(date("m/d/Y", now()));

Till Next Time