如何在 Zend Studio 7 (for Eclipse) 中生成驼峰式 getter 和 setter?

发布于 2024-09-07 06:21:36 字数 539 浏览 3 评论 0原文

示例:

protected $_labelName = null;

应该生成

public function getLabelName()
{
    $this->_labelName;
}

public function setLabelName($labelName)
{
    $this->_labelName = $labelName;
    return $this;
}

但它是生成

public function get_labelName()
{
    return $this->_labelName;
}

public function set_labelName($_labelName)
{
    $this->_labelName = $_labelName;
    return $this;
}

正如您所看到的 - 它看起来不同,但我没有找到如何更改方法名称和修剪设置方法参数名称的方法。

Example:

protected $_labelName = null;

Should generate

public function getLabelName()
{
    $this->_labelName;
}

public function setLabelName($labelName)
{
    $this->_labelName = $labelName;
    return $this;
}

But it is generates

public function get_labelName()
{
    return $this->_labelName;
}

public function set_labelName($_labelName)
{
    $this->_labelName = $_labelName;
    return $this;
}

As you could see - it looks different but i didn't found the way how to change the method name and to trim the set method param name.

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

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

发布评论

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

评论(2

微暖i 2024-09-14 06:21:36

一个简单的解决方法:将您的 var 命名为 $labelName,然后生成 getter 和 setter,最后重构/重命名该 var,使其成为 $_labelName。适用于 Zend Studio 7.2(刚刚下载了试用版来检查它:p)。

A simple workaround : name your var $labelName, then generate getters and setters, and finally refactor/rename the var so it becomes $_labelName. Works in Zend Studio 7.2 (just downloaded the trial to check it :p).

泪意 2024-09-14 06:21:36

更改方法主体(和注释)

Window > Preferences > PHP > Editor > Templates

您可以通过单击“我不认为您可以更改方法签名”来 。我将向 Zend 开具票证并询问更改方式。 Zend Framework 的首要 IDE 生成不符合 ZF 代码约定的 getter 和 setter,这有点烦人。

编辑 这已在 Zend Studio 8 中修复。当您生成 Getters/Setter 时,它们不会包含指示私有或受保护可见性的前导下划线。成员名称后面的任何下划线都将被保留,例如 $_foo 将生成 getFoo()setFoo($_foo),而 $_foo_bar(根据 ZF 约定无效)将生成 getFoo_bar()setFoo_bar($_foo_bar)

You can change the method body (and comment) by clicking

Window > Preferences > PHP > Editor > Templates

I don't think you can change the method signature though. I'll open a ticket with Zend and ask for a way to change it. It's kinda annoying that the premier IDE for Zend Framework generates getters and setters that are not in compliance with the ZF code convention.

EDIT This was fixed in Zend Studio 8. When you generate Getters/Setters, they will not include the the leading underscore indicating private or protected visibility. Any underscores later in the member name will be kept, e.g. $_foo will generate getFoo() and setFoo($_foo), while $_foo_bar (which is invalid by ZF convention) will generate getFoo_bar() and setFoo_bar($_foo_bar)

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