Zend framework 2: How to use view helper in other view helper
zend-framework2
Solution
As long as your helper extends the abstract helper class, the View object is injected into it, and you can access other helpers from there.
class HelpMe2 extends AbstractHelper
{
public function __invoke()
{
return '<p>' . $this->view->helpMe1('Text') . '</p>';
}
}
Problem
Is it possible to use view helper in another view helper? We have to view helpers: HelpMe1 ``` use Zend\View\Helper\AbstractHelper; class HelpMe1 extends AbstractHelper { public function __invoke($arg) { return $arg; } } ``` HelpMe2 ``` use PathTo\HelpMe1; use Zend\View\Helper\AbstractHelper; class HelpMe2 extends AbstractHelper { public function __invoke() { return '<p>' . new HelpMe1('Text') . '</p>'; } } ``` If this is possible what it the base practice for that? Regards,