Eclipse 自动完成 $this->test

发布于 2024-10-09 05:40:10 字数 417 浏览 0 评论 0原文

当这个属性没有在同一个 php 文件中定义时,我们如何才能对属性进行自动完成呢?

例如,使用 ZF,在控制器中我们可以执行此操作

$this->view->voiture = new My_Voiture();

,在视图中,我们有一个变量 $this->voiture,但我如何才能在其上实现自动完成?

我尝试 /* @var $this->voiture My_voiture */ 但没有结果...

目前,我的答案是在视图中执行,

/* @var $voiture My_Voiture */
$voiture = $this->voiture;

但我不喜欢它。你有好点了吗?

How can we have autocomplete on property when this one isn't define in the same php file.

for example, with ZF, in the controller we can do

$this->view->voiture = new My_Voiture();

and in the view, we have a variable $this->voiture, but how can i have the autocomplete on it ?

i try /* @var $this->voiture My_voiture */ and no result...

for the moment, my answer is to do in the view

/* @var $voiture My_Voiture */
$voiture = $this->voiture;

but i don't like it. Have you better ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-10-16 05:40:10

我认为,在原始源中记录原始变量实际上是最好的方法。其他文件中视图的所有其他用法都应该通过在其一个源记录它来继承自动完成功能。

为了获得我期望的自动完成功能,我会执行以下操作:

  • 在 My_Voiture 类中,确保您有变量和方法的文档块。从技术上来说,这对于自动完成本身来说并不是必需的,但它允许自动完成弹出窗口包含更多信息,而不仅仅是变量和方法。
  • 在 My_View 类中,首先声明(未使用)$voiture,我将放置将其类型标识为 My_Voiture 的 @var 文档块。这应该足以使其 $voiture 变量的任何使用都继承 My_Voiture 的属性。
  • 在 My_Controller 类中,首先声明(未使用)$view 的位置,我将放置将其类型标识为 My_View 的 @var 文档块。这应该足以使其 $view 变量的任何使用继承 My_View 的属性。

现在,在您期望对 $this->view->voiture 进行自动补全的代码文件中——如果其中没有任何内容表明 $this 是一个 My_Controller 对象,那么当 Eclipse 尝试执行以下操作时,它无处可启动:识别 $this (然后是它的所有属性)。我想我以前见过一些 MVC 代码,这种情况很普遍,因为很多“动态”属性依赖于“变量”,比如 $$foo。

Documenting the original variable in its original source is actually the best way to go, I think. All other usages of your view in other files should inherit the autocompletion just by documenting it at its one source.

In order to get the autocompletion that I would expect, I would do these things:

  • In the My_Voiture class, make sure you have docblocks for your variables and your methods. This isn't technically necessary for the autocompletion itself, but it will allow the autocompletion popups to contain much more info that just variables and methods.
  • In the My_View class, where $voiture is first declared (not used), I would place the @var docblock that identifies its type as My_Voiture. This should be enough to make any usage of its $voiture variable inherit the properties of My_Voiture.
  • In the My_Controller class, where $view is first declared (not used), I would place the @var docblock that identifies its type as My_View. This should be enough to make any usage of its $view variable inherit the properties of My_View.

Now, in your code file where you are expecting autocompletion on $this->view->voiture -- if it has nothing in it that indicates that $this is a My_Controller object, then Eclipse has nowhere to start when it tries to identify $this (and then all of its properties). I think I've seen some MVC code before where this is prevalent, due to much "dynamic" properties relying on "variable variables" like $$foo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文