While accessing variables in local function within view phtml file I get this popular error
Using $this when not in object context
I want to know is there any way by which I can bulk copy all the variables and objects in Variables container data structure of ViewModel defined in Controller, as local variables and objects to view so I can use them in local functions?
In otherwords, like someCreateVariablesFromViewModelArray method to call in phtml. Because I have lot of data in ViewModel Variables container array in Zend Framework 2.
It sounds like you have something like this:
//view + some html
<?php
function something() {
//do sth
};
?>
<p>some text</p>
<?php something() ?>
I recommend writing a view-helper. There you have access to the view or can inject components you need.
You can inject $this into your function:
//view + some html
<?php
function something($view) {
//do sth
};
?>
<p>some text</p>
<?php something($this) ?>
<?php
$something = function() use ($this) {
//do sth
};
?>