1、自定义View Helper
在module的Core/Helper下新建自定义的View Helper类--SpecialPurpose.php
<?php namespace Core\Helper; use Zend\View\Helper\AbstractHelper; /** * View Helper */ class SpecialPurpose extends AbstractHelper { public function __invoke($in) { $output = sprintf ("I have seen 'The Jerk' %d time(s).", $in); return htmlspecialchars ($output, ENT_QUOTES, 'UTF-8'); } }
?
2、注册自定义View Helper
修改module下的module.config.php文件,在此文件的数组中添加以下代码:
'view_helpers' => array ( 'invokables' => array ( 'SpecialPurpose' => 'Core\Helper\SpecialPurpose' ) ),
?
3、在View中使用
<?php echo $this->specialPurpose(100); ?>
?