ZF2: Objects passed to ViewModel constructor get converted to array

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2: Objects passed to ViewModel constructor get converted to array

dlu-gs
I am passing objects from my controllers to my views like this:

//$myForm is an object Zend\Form\Form
$viewModel  = new ViewModel(array('form' => $myForm));
return $viewModel;

This worked as expected until PR#2074. But now the ViewModel variable 'form' is converted to an array. (It gets converted in ViewModel::setVariables() method in the new 'overwrite' condition.)

If I set the ViewModel variable like this:

$viewModel  = new ViewModel();
$viewModel->setVariable('form', $myForm);
return $viewModel;

everything is ok.

Is this an intended behaviour?
David Lukas (dlu-gs)
www.zfdaily.com
Reply | Threaded
Open this post in threaded view
|

Re: [fw-core] ZF2: Objects passed to ViewModel constructor get converted to array

weierophinney
Administrator
-- dlu-gs <[hidden email]> wrote
(on Thursday, 02 August 2012, 07:17 AM -0700):

> I am passing objects from my controllers to my views like this:
>
> //$myForm is an object Zend\Form\Form
> $viewModel  = new ViewModel(array('form' => $myForm));
> return $viewModel;
>
> This worked as expected until PR#2074. But now the ViewModel variable 'form'
> is converted to an array. (It gets converted in ViewModel::setVariables()
> method in the new 'overwrite' condition.)
>
> If I set the ViewModel variable like this:
>
> $viewModel  = new ViewModel();
> $viewModel->setVariable('form', $myForm);
> return $viewModel;
>
> everything is ok.
>
> Is this an intended behaviour?

No. Fixed in master now.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]