//./module/Core/src/Core/Helper/SpecialPurpose.phpnamespace Core\Helper; use Zend\View\Helper\AbstractHelper; class SpecialPurpose extends AbstractHelper{ protected $count = 0; public function __invoke() { $this->count++; $output = sprintf("I have seen 'The Jerk' %d time(s).", $this->count); return htmlspecialchars($output, ENT_QUOTES, 'UTF-8'); }}
2、注册自定义视图
// ./module/Core/config/module.config.php return array( 'view_helpers' => array( 'invokables' => array( // generic view helpers 'specialPurpose' => 'Core\Helper\SpecialPurpose', ), ),);
3、在view 中使用
specialPurpose(); ?>