0

I'm using zend framework 2 with PHPStorm 7.1.2

Inside my view I want to have code completion for $this->form().

Here is the code:

Controller:

public function indexAction() {
    $viewModel = new ViewModel();
    $form = new SearchForm('search');
    $viewModel->setVariable('form', $form);
    return $viewModel;
}

View:

<?php
/**
 * @var \Zend\View\Renderer\PhpRenderer $this
 * @var \Application\Form\SearchForm $form
 */
?>

<?php $form->setAttribute(...); ?>
<?php $form->prepare(); ?>
<?php $this->form()->openTag($form); ?>

...

<?php $this->form()->closeTag(); ?>

In my view I got code completion on e.g. $this->url(...); and on $form->setAttribute(...);.

How must I annotate my file to get code completion on $this->form()?

PHPStorm tells something about

Method 'form' not found in class Zend\View\Renderer\PhpRenderer

...

Thanks, Jens

jhartlep
  • 23
  • 4
  • The only way right now is via `@method' PHPDoc tag in PHPDoc comment for your Controller/View/Renderer (whatever `$this` is in your view file) class (sorry, not ZF2 user). Because that class is most likely part of ZF2, you cannot really edit it. My only suggestion then would be to copy that class elsewhere (within your project) and add `@method` tags there. IDE will warn you that you have 2 classes with the same name .. but it's better than having no completion. – LazyOne Feb 07 '14 at 14:21

1 Answers1

1

$this->form() as well as $this->formXY() are ViewHelpers and you won't get any kind of type-hinting for those.

Sam
  • 16,435
  • 6
  • 55
  • 89
  • 1
    +1 To elaborate as to why; the `$this->form()` method **does not exist** on the renderer as it is [caught via the magic `__call()` and mapped to the required plugin](https://github.com/zendframework/zf2/blob/master/library/Zend/View/Renderer/PhpRenderer.php#L394) (`Zend\Form\View\Helper\Form` in this case) – AlexP Feb 08 '14 at 17:12