March 29, 09 by Gabi Solomon
Many times when i use Zend_View i have to include view files that are in the same directory, and i am forced to type in the same path over again. Which is and isnt so much work, but during development i often have to place those files in a different folder or rename one of the folders. In witch case i would be forced to change those path i gave in the view file.
This is why i wrote a small View_Helper to return the current view folder.
Unfortunately this will not work on a Zend framework out of the box, it will require some modifications to Zend_View_Abstract.
I have placed the code on ZF Snippets website, a project that i really like, and i would ask you to place any comments and suggestions for this helper on that webpage.
[ZF Snippets code]
Cheers
January 18, 09 by Gabi Solomon
Important
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.
PHP:
-
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