views:

42

answers:

1

I have a simple Zend Framework that has a view script to add records to the database. This is a silly question IMHO, but how can I use the add view script to edit the record as well??

I have played around with a few scenarios to no avail.

Thanks,

Steve

+1  A: 

Per Matt S' comment, the method you're looking for is Zend_Form::populate(). There are some notes about it in the documentation: Populating and Retrieving Values.

Basically, you use it like this in the controller:

$form = new Form_Person();
// get the data from somewhere
if($id = $this->getRequest()->getParam('id') && $model->find($id)) {
  // really, use data from the model here
  // but the populate() -method can take any array as an argument
  $form->populate(array(
    'name' => 'Dolph',
    'age' => '52'
  ));
}
$this->view->form = $form;

and in your view, as usual:

<?= $this->form ?>

So the array could be for example the result of Zend_Db_Table_Row_Abstract::toArray() with column names matching to the names you gave the form elements.

chelmertz