简体   繁体   中英

How to generate camelized getters and setters in Zend Studio 7 (for Eclipse)?

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.

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, eg $_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)

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM