laravel PHPStorm 自动完成树枝变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26274704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:15:25  来源:igfitidea点击:

PHPStorm autocomplete twig vars

phplaravelphpstorm

提问by Felice Ostuni

I'm using PHPStorm 8.1 as IDE in a php project (laravel 4.1 project with twig on view side)

我在 php 项目中使用 PHPStorm 8.1 作为 IDE(laravel 4.1 项目,视图侧有树枝)

Will be great to have an autocomplete hint on vars on "twig side" like you can see here on this phpstorm plugin for symfony2:
http://symfony2-plugin.espend.de/languages/twig/index.html#phptypes

在“树枝侧”的变量上有一个自动完成提示会很棒,就像你可以在 symfony2 的这个 phpstorm 插件上看到的一样:http://symfony2-plugin.espend.de/languages/twig/index.html#phptypes

Basically in my twig view I declare the var "type" using a comment, then I would see hints on my model (farmaco):

基本上在我的树枝视图中,我使用注释声明了 var“type”,然后我会看到我的模型(farmaco)的提示:

   {# farmaco \Farmaco #}
   {% farmaco.  %} <-- I would see hints -->

Note: I'm not using Symfony, however I've the symfony plugin installed but the autocomplete doesn't work for me on twig files for my laravel project.

注意:我没有使用 Symfony,但是我已经安装了 symfony 插件,但是自动完成功能对我的 laravel 项目的树枝文件不起作用。

回答by Potherca

You seem to be missing the @varannotation. The correct form would be:

您似乎缺少@var注释。正确的形式是:

{# @var foo \FooService #}
{{ foo. }} <!-- press CTRL+SPACE for typehints -->

I got this working for a non-symfony project without issues. Be sure to check that the symfony plugin is actually enabled for the project (it isn't by default) and restart the IDE after you enable it.

我让它在一个非 symfony 项目中工作而没有问题。请务必检查项目是否实际启用了 symfony 插件(默认情况下并非如此)并在启用后重新启动 IDE。

Also make sure that the type-hint point to the fully qualified class name.

还要确保类型提示指向完全限定的类名



As a sidenote, I have not(yet) gotten this to work for properties, i.e. foo.bar.*when the property is accessed through magic (using __get). For those instances the property needs to be put into a variable of its own:

作为旁注,我还没有(还)让它对属性起作用,即foo.bar.*当通过魔法(使用__get)访问属性时。对于这些实例,需要将属性放入它自己的变量中:

{# @var foo \FooService #}
{{ foo.bar. }} <!-- no typehints for bar :-( -->
{% set bar = foo.bar %}
{# @var bar \BarService #}
{{ bar.  }} <!-- press CTRL+SPACE for typehints :-) -->