Reputation: 486
I am migrating my old application to the new Zend Framework 2.0. My app uses it just as a library (no Zend\Application use or anything of the MVC part), and I have problems using the Form Helpers. So, I ended having 2 questions:
Upvotes: 0
Views: 672
Reputation: 621
You can add helper by calling setFactory() from HelperPluginManager.
$renderer = new \Zend\View\Renderer\PhpRenderer();
$renderer->getHelperPluginManager()->setFactory('specialPurpose', function () {
return new SpecialPurpose();
});
echo $renderer->specialPurpose();
echo $renderer->specialPurpose();
echo $renderer->specialPurpose();
class SpecialPurpose extends \Zend\View\Helper\AbstractHelper {
protected $count = 0;
public function __invoke() {
$this->count++;
$output = sprintf("Called %d time(s).", $this->count);
return htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
}
}
Upvotes: 3