credy/yii2-rename-behavior

Rename attributes on models.

Installs: 18

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:yii2-extension

pkg:composer/credy/yii2-rename-behavior

1.0.0 2025-11-13 15:20 UTC

This package is auto-updated.

Last update: 2025-11-13 13:21:14 UTC


README

With this behavior, you can rename attributes on components in Yii2

Usage

    public function behaviors()
    {
        return [
            'renameBehavior' => \credy\behavior\rename\RenameBehavior::class,
            'renames' => [
                'renamedAttributeName' => 'realAttributeName'
            ]
        ]
    }

You can also define get and set methods that modify the data

    public function behaviors()
    {
        return [
            'renameBehavior' => \credy\behavior\rename\RenameBehavior::class,
            'renames' => [
                'renamedAttributeName' => 'realAttributeName'
            ],
            'getMethod' => [self::class, 'getModifiedAttribute'],
            'setMethod' => [self::class, 'setModifiedAttribute'],
        ];
    }

    public static function getModifiedAttribute($value, $attributeName)
    {
        // do some modifications here
        return 'modified attribute value';
    }

    public static function setModifiedAttribute($value, $attributeName)
    {
        // do some modifications here
        return 'modified attribute value';
    }