Reputation: 5363
If I have a view and want to see all the set variables for the particular view, how would I do it?
Upvotes: 3
Views: 4678
Reputation: 1618
There's a more elegant way: $this->viewModel()->getCurrent()->getVariables();
For a nested viewModel: $this->viewModel()->getCurrent()->getChildren()[0]->getVariables();
Upvotes: 7
Reputation: 632
In my case, I had a need to load a partial view from within another view. This was very easy, actually. Instead of worrying about getting the variables to pass through from a parent view to a child, simply pass the parent view object.
<?php echo $this->partial('my-view.phtml', $this); ?>
Upvotes: 1
Reputation: 69957
Variables assigned to a Zend_View
object simply become public properties of the view object.
Here are a couple of ways to get all variables set in a particular view object.
From within a view script:
$viewVars = array();
foreach($this as $name => $value) {
if (substr($name, 0, 1) == '_') continue; // protected or private
$viewVars[$name] = $value;
}
// $viewVars now contains all view script variables
From a Zend_View
object in a controller:
$this->view->foo = 'test';
$this->view->bar = '1234';
$viewVars = get_object_vars($this->view);
// $viewVars now contains all public properties (view variables)
The last example would work just as well for a view object created manually using $view = new Zend_View();
Upvotes: 9