How to change generate getxxx and isxxx method for boolean field

Hi,

How i can change settings to generate both is and get method when my field is boolean?

Example:
I create a field $myBoolField As boolean
So i want to generate at the same time getMyBoolField() and isMyBoolField() methods

Thanks for your help

1 comment

Easy.

1. "Settings/Preferences | Editor | File and Code Templates | Code | PHP Getter Method"

2. You need to edit the template: a) change automatic "get/is" prefix to hardcoded "get" and b) add the template for "is" below it surrounded by condition (so that it will only be used for boolean fields).

Something like this (adjust empty lines/etc as needed)

/**
 * @return ${TYPE_HINT}
 */
public ${STATIC} function get${NAME}()
{
#if (${STATIC} == "static")
    return self::$${FIELD_NAME};
#else
    return $this->${FIELD_NAME};
#end
}
#if (${TYPE_HINT} == "boolean")

/**
 * @return ${TYPE_HINT}
 */
public ${STATIC} function is${NAME}()
{
#if (${STATIC} == "static")
    return self::$${FIELD_NAME};
#else
    return $this->${FIELD_NAME};
#end
}
#end

 

0

Please sign in to leave a comment.