Llamar a un View Helper desde otro View Helper en Zend Framework

Via: http://www.leftcolumn.net/2009/01/15/calling-a-view-helper-from-inside-another-view-helper-in-zend-framework/

[Actualizado 8 Abril 2009] Apparently as of 1.7.6 $this->view->[helperName()] now works with no extra work required so the info in this post is only necessary if you’re using <= 1.7.5. Thanks to Mike van Lammeren for the heads up,  see Mike’s comment below.

To call a view helper from within another view helper, you need to give the helper some, er, help. Helpers will try to call a function called setView to set up $_view, so just add it:

Add these lines to the view helper:

private $_view;
public function setView($view) {
$this->_view = $view;

then to call the View Helper you need, use $this->_view->anyHelperYouLike();

Edit: I found this information somewhere on the web, but can’t remember the source. Any information appreciated!



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s