问题描述
我在 ZF2 应用程序中扩展了 PhpRenderer 类,如下所示:
I have extended the PhpRenderer class in my ZF2 application like this:
namespace MyLib\View\Renderer;
class PhpRenderer extends \Zend\View\Renderer\PhpRenderer
{
}
我不想添加新的渲染策略,我只是将 PhpRenderer 扩展为 为我的视图助手添加一些@method phpdoc.
I don't want to add a new rendering strategy, I just extend the PhpRenderer to add some @method phpdoc for my viewhelpers.
如何用扩展的 PhpRenderer 替换标准的 PhpRenderer,以便它用于渲染我的视图脚本?
How can I replace the standard PhpRenderer with my extended PhpRenderer so it will be used to render my viewscripts?
推荐答案
如果您的自定义类包含的是 @method
声明,那么您不需要替换 php 渲染器类.只需确保使用 @var
文档块,您的 IDE 就会知道该做什么:
If all your custom class contains is @method
declarations then you don't need to replace the php renderer class. Just make sure to use the @var
docblock and your IDE will know what to do:
记录视图文件中 $this
变量的类型:
Document the type for the $this
variable in your view files:
<!-- in a view file -->
<?php /* @var $this MyLib\View\Renderer\PhpRenderer */ ?>
<?= $this->myCustomViewHelper() ?>
记录视图助手、类等的各个变量或属性:
Document individual variables or properties for view helpers, classes, etc:
class SomeHelper extends AbstractHelper
{
/** @var \MyLib\View\Renderer\PhpRenderer */
protected $view;
public function __invoke()
{
$this->view->myCustomViewHelper();
}
}
这篇关于如何在 ZF2 应用程序中替换 PhpRenderer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!