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
Post a Comment