1、自定义视图类
01 |
//./module/Core/src/Core/Helper/SpecialPurpose.php |
02 |
namespace
Core\Helper; |
03 |
use Zend\View\Helper\AbstractHelper; |
04 |
class SpecialPurpose extends AbstractHelper |
05 |
{ |
06 |
protected $count =
0; |
07 |
public function __invoke() |
08 |
{ |
09 |
$this -> count ++; |
10 |
$output =
sprintf( "I
have seen 'The Jerk' %d time(s)." , $this -> count ); |
11 |
return htmlspecialchars( $output ,
ENT_QUOTES, 'UTF-8' ); |
12 |
} |
13 |
} |
2、注册自定义视图
01 |
//
./module/Core/config/module.config.php |
02 |
03 |
return array ( |
04 |
'view_helpers' => array ( |
05 |
'invokables' => array ( |
06 |
//
generic view helpers |
07 |
'specialPurpose' => 'Core\Helper\SpecialPurpose' , |
08 |
), |
09 |
), |
10 |
); |
3、在view 中使用
1 |
<?php echo $this ->specialPurpose();
?> |