2017 © Pedro Peláez
 

yii2-extension yii2-attrswatcher

Sometimes you want on change some attribute set value to another attribute. This extention provide that.

image

lebedyncrs/yii2-attrswatcher

Sometimes you want on change some attribute set value to another attribute. This extention provide that.

  • Monday, August 8, 2016
  • by lebedyncrs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Attribute watcher for Yii2

Installation

The preferred way to install this extension is through composer., (*1)

Either run, (*2)

php composer.phar require --prefer-dist lebedyncrs/yii2-attrswatcher

or add, (*3)

"lebedyncrs/yii2-attrswatcher": "*"

to the require section of your composer.json., (*4)

Usage

Sometimes you want on change some attribute set value to another attribute. This behavior provide that.
Attach behavior to model:, (*5)

public function behavior(){
  [
    'class' => AttrsWatcherBehavior::className(),
    'attributes' => [
          'Status' => [
              AttrsWatcherBehavior::ATTRIBUTE => 'ClosedOn',
              AttrsWatcherBehavior::FROM => null
              AttrsWatcherBehavior::TO => 1
            ],
            'Rel_DealStage' => [
                   AttrsWatcherBehavior::ATTRIBUTE => 'LastStageChange',
            ]
      ]
  ]
}

With this configuration behavior set current timestamp to ClosedOn attribute when Status will be changed from null to 1. When Rel_DealStage will changed LastStageChange will containt current timestamp., (*6)

public function behavior(){
  [
    'class' => AttrsWatcherBehavior::className(),
    'attributes' => [
          'Status' => [
              AttrsWatcherBehavior::ATTRIBUTE => 'ClosedOn',
              AttrsWatcherBehavior::FROM => null
              AttrsWatcherBehavior::TO => 1
            ],
            'Rel_DealStage' => [
                   AttrsWatcherBehavior::ATTRIBUTE => 'LastStageChange',
            ]
      ],
      'values' => [
          'ClosedOn' => 'my own value',
          'LastStageChange' => 'my own value'
      ]
  ]
}

As you can see from above example you can set own value for each attribute.
Also you can change default value for all attributes:, (*7)

public function behavior(){
  [
    'class' => AttrsWatcherBehavior::className(),
    'attributes' => [
          'Status' => [
              AttrsWatcherBehavior::ATTRIBUTE => 'ClosedOn',
          ]
      ],
      'values' => function(){
        return time()-100;
      }
  ]
}

The Versions

08/08 2016

dev-master

9999999-dev

Sometimes you want on change some attribute set value to another attribute. This extention provide that.

  Sources   Download

BSD-3-Clause

The Requires

 

by Sergij Lebedyn

yii2 attribute watcher yii2-propery-observer property-observer propertyobserver yii2-propertyobserver