php - How do I push value into an array that's defined in the viewModel? -


i using zend framework 2, , plan on achieving is:

i have class, has viewmodel defined. need create array viewmodel , set values array, can access in view.

so, in class, have following:

$viewmodel = new zend\view\model\viewmodel(); $viewmodel->setvariable('fields', array( )); 

this means, creating array called formfields accessible in view. now, how push value array, model class? trying following doesn't seem work:

$viewmodel->setvariable('fields[]', $field); 

thanks,

why not pass during declaration:

$viewmodel->setvariable('fields', array(     'key' => 'value',     ... )); 

or assign value variable, need it, , set on viewmodel object.

you can variable, change it's value , set again in place. e.g.:

$arr = $viewmodel->gevariable('fields'); array_push($arr, 'value'); $viewmodel->setvariable('fields[]', $arr); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -