Setting up defaults to edit form 30/01/2012
Setting up defaults in factory component / form is wrong. What’s the right way to do so?
class FooPresenter extends BasePresenter { protected function loadItem($id) { $item = $this->getContext()->itemService->find($id); if (!$item) { $this->flashMessage("Item with id $id does not exist", 'error'); $this->redirect('default'); // aka items list } return $item; } protected function createComponentRecordForm() { $form = new Form; $form->addText(...); // ... } public function actionEdit($id) { $item = $this->loadItem($id); $defaults = $this->someMagicHere($item); $this['recordForm']->setDefaults($defaults); } }
Setting up defaults in factory component / form is wrong. What’s the right way to do so?
class FooPresenter extends BasePresenter
{
protected function loadItem($id)
{
$item = $this->getContext()->itemService->find($id);
if (!$item) {
$this->flashMessage("Item with id $id does not exist", 'error');
$this->redirect('default'); // aka items list
}
return $item;
}
protected function createComponentRecordForm()
{
$form = new Form;
$form->addText(...);
// ...
}
public function actionEdit($id)
{
$item = $this->loadItem($id);
$defaults = $this->someMagicHere($item);
$this['recordForm']->setDefaults($defaults);
}
}