Zend Framework View partial without reseting variables
by Gabi SolomonImportant
Ignore this solution, there is already a solution in ZF implemented in View as Jani Hartikainen pointed out in the comment below.
Its $this->render('...');
Zend Framework has a view helper called partial that you can use to render other views in your view file.
This is very useful for reusing the html code.
The problem i sometimes faced with that partial helper is that it resets all the variables and you need to specify them as an array parameter if you want them to be available in the partial view rendered.
The solution
To overcome this all you need to do is make a new view helper ... i called mine GSD_View_Helper_Render witch extends the Zend_View_Helper_Partial and overwrites the methods that clones the view and resets the variables.
-
class GSD_View_Helper_Render extends Zend_View_Helper_Partial {
-
-
public function cloneView()
-
{
-
$view = clone $this->view;
-
// $view->clearVars(); ... this was the line that resets all the variables.
-
return $view;
-
}
-
}
Thats it. Hope this is of help to you.
Cheers
Related Posts
-
bogdanghervan
-
Gabi Solomon
-
ari
-
Gabi Solomon
-
Matthew Weier O'Phinney
-
Gabi Solomon
-
Jani Hartikainen

