-- WebCorp s.r.o | Jan Juříček <[email protected]> wrote
(on Tuesday, 24 March 2009, 11:55 AM +0100):
> Zend_Form::setDefault() strictly requires an array. What is the reason for
> that? I think it would be very good if also stdClass object could be passed.
Why?
The more requirements we make, the harder it is to maintain the
component. It's trivial to do the following:
$form->setDefaults((array) $object);
which would accomplish what you're attempting to do, without changing
the actual object at all.'
> Maybe I'm also missing something?
>
> I have a Zend_Form with some input fields, I also have a stdClass object,
> where variable names match to input field names and those variables have
> values I'd like to pre-fill to those input fields. I think that is really a
> general case for editing some database record.
>
> stdClass object is returned by my model class method:
>
> /* cut from the controller script */
> public function detailAction()
> {
> $model = $this->_getModel();
> $this->view->client =
> $model->getClientDetail($this->_request->getParam('users_id'));
> }
>
> As you can see, I'm using the result of Model_Client::getClientDetail() in
> my view scripts. That works great. Since it returns all the data I need in
> the edit form, I'd like to use the exact same model method to get values for
> the edit form.
>
> Is there a problem in my process? How should this generally be done? I don't
> exactly like the idea to convert stdClass to an array just because
> setDefault method just won't accept stdClass by now...
>
> Thanks for every response.
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/