I currently have the following code in a ZF application, to set the values of a Form based on a rowset retrieved from a Db-Table.
$form->forename->setValue($footerContactDetails->forename);
$form->surname->setValue($footerContactDetails->surname);
$form->telephone->setValue($footerContactDetails->telephone);
$form->mobile->setValue($footerContactDetails->mobile);
$form->fax->setValue($footerContactDetails->fax);
$form->email->setValue($footerContactDetails->emailAddress);
$form->address1->setValue($footerContactDetails->address1);
$form->address2->setValue($footerContactDetails->address2);
$form->address3->setValue($footerContactDetails->address3);
$form->townCity->setValue($footerContactDetails->townCity);
$form->region->setValue($footerContactDetails->region);
As the object element names from the rowset match the form elements, what I'd like to do is the following:
foreach ($footerContactDetails as $key=>$value) {
$form->$key->setValue($value);
}
However this provides the following error message:
Fatal error: Call to a member function setValue() on a non-object
I expect this question is more related to OOP PHP in general and not the just ZF.
So how can I set these form values using a foreach?
Many thanks