IDE 中 CakePHP 的代码完成

发布于 2024-12-02 11:56:44 字数 566 浏览 1 评论 0原文

有人建议我“使用代码完成”,我意识到虽然我的 IDE 具有代码完成功能,但它无法识别从 CakePHP 框架继承的大部分方法和变量,尤其是视图的 Helper 方法。我正在使用 PhpED,但它的代码完成似乎应该像在 Eclipse 和其他编辑器中一样工作。

我遵循了这个建议,但没有成功;我创建了一个 helpers.php 文件,其中包含所有帮助程序的定义,并将其包含在项目中,但代码完成仍然无法与帮助程序一起使用。

我认为部分问题是 Mark Story 的帖子来自旧版本的 cake(我使用的是 Cake 1.3),因此我更新了 Helpers 的定义,如下所示:

$this->Form = new FormHelper();

但任何视图仍然没有代码完成。有什么办法可以让这个工作吗?除了 Helpers 之外,我真的很希望完成像 Model->find() 这样的函数,但这些函数也不起作用。

Someone recommended I "use code completion" and I realized that while my IDE has code completion, it doesn't recognize the large majority of methods and variables inherited from CakePHP's framework, most notably the Helper methods for views. I'm using PhpED but it seems like it's code completion is supposed to work just as it does in eclipse and other editors.

I followed this advice to no avail; I created a helpers.php file with definitions of all the helpers and included it in the project but the code completion still doesn't work with the Helpers.

I think part of the problem is Mark Story's post is from an old version of cake (I am on Cake 1.3) so I updated the definitions of the Helpers to look like this:

$this->Form = new FormHelper();

But there's still no code completion for any of the views. Is there any way to make this work? In addition to the Helpers I'd really like completion for functions like Model->find() but those don't work either.

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

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

发布评论

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

评论(3

故事还在继续 2024-12-09 11:56:44

正如您可能从几个工作代码完成脚本中注意到的那样,您始终需要将它们放入范围内。
意义:
你需要用它们应该使用的类来包装它们。
至少对于组件和模型等而言。
对于助手来说,这更困难,因为它们位于视图范围内,而视图/布局中的 IDE 无法直接使用/可见。
我使用应用程序助手作为范围。无论如何对我有用。更正确的是 View 类。

不管怎样,对于帮助者来说可能没有万无一失的方法。不过,大多数 IDE 应该都能识别它。

例如我的(用于 phpdesigner):
http://www.dereuromark.de/tag/code-completion/

但是其他人也类似。

as you might have noticed from several working code completion scripts out there you always need to put them into scope.
meaning:
you need to wrap them with the class they should be used in.
at least for components and models etc.
for helpers this is more difficult since they would be in the View scope which is not directly available/visible for IDEs in the views/layouts.
i use the app helper as scope. works for me anyway. more correct would be View class.

either way there is probably not a foolproof method for helpers. most IDE should pick it up, though.

e.g. mine (for phpdesigner):
http://www.dereuromark.de/tag/code-completion/

but the others are similar.

薄荷→糖丶微凉 2024-12-09 11:56:44

对于 PhpED,您必须执行以下操作才能启用 $this 的自动完成功能。

假设您想在控制器中使用 $this 来完成类似的事情

$this->项目->国家/地区->getCountryName($countryId)

首先在类定义之前添加此 PhpDoc 标签

/**
* @property-read Project $Project
*/
class ProjectsController....

现在输入 $this->Project 应该可以按预期工作。
接下来是Project模型类。

在这里添加以下代码,再次在类定义之前

/**
* @property-read Country $Country
*/
class Project extends AppModel

现在 $this->Project->Country->getCountryName($countryId) 可以工作。该方法并不是 100% 如我所愿,因为 PhpED 自动完成按字母顺序排序,因此任何以 A 或 B 开头的类都将显示在 Country 模式的方法之前。

For PhpED you have to do the following to enable Autocompletion for $this.

Lets say you want to use $this in a Controller for something like this

$this->Project->Country->getCountryName($countryId)

First add this PhpDoc tag before the class definition

/**
* @property-read Project $Project
*/
class ProjectsController....

Now typing $this->Project should work as intended.
Next up is the Project model class.

In here add the following code, again before the class definition

/**
* @property-read Country $Country
*/
class Project extends AppModel

Now $this->Project->Country->getCountryName($countryId) works. The method is not 100% as i would like it, as PhpEDs Autocompletion sorts alphabetically, so any class starting with A or B will be shown before the methods of the Country mode.

自我难过 2024-12-09 11:56:44

这不是您问题的答案。

我会推荐 gedit,带有单词补全插件。虽然不是 IDE 级别的“代码完成”插件,但它在从源文件中提取单词并使用它们填充其单词列表方面做得非常出色。由于构建单词列表的有机方法,它“适用于”几乎任何框架、任何语言。 (无耻地插入我的博客,其中有很多关于 gedit 如何成为最好的编辑器的提示和技巧:http://davidsouther.com/2011/08/gedit-tips-tricks/

This is not an answer to your question.

I would recommend gedit, with the word completion plugin. While not an IDE-level "Code Completion" plugin, it does an awesome job at picking up words from your source files and using those to populate its word list. It "just works" for nearly any framework, any language, because of that organic approach to building the word list. (Shameless plug to my blog, with lots of tips and tricks for how gedit can be the best editor out there: http://davidsouther.com/2011/08/gedit-tips-tricks/)

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