diff --git a/docs/guide/intro-upgrade-from-v1.md b/docs/guide/intro-upgrade-from-v1.md index 46f90df101..79bd0bbbae 100644 --- a/docs/guide/intro-upgrade-from-v1.md +++ b/docs/guide/intro-upgrade-from-v1.md @@ -459,13 +459,45 @@ public function init() } ``` -There where some problems with overriding the constructor of an ActiveRecord class in 1.1. These are not present in +There were some problems with overriding the constructor of an ActiveRecord class in 1.1. These are not present in version 2.0 anymore. Note that when adding parameters to the constructor you might have to override [[yii\db\ActiveRecord::instantiate()]]. There are many other changes and enhancements to Active Record. Please refer to the [Active Record](db-active-record.md) section for more details. +Active Record Behaviors +----------------------- + +In 2.0, we have dropped the base behavior class `CActiveRecordBehavior`. If you want to create an Active Record Behavior, +you will have to extend directly from `yii\base\Behavior`. If the behavior class needs to respond to some events +of the owner, you have to override the `events()` method like the following, + +```php +namespace app\components; + +use yii\db\ActiveRecord; +use yii\base\Behavior; + +class MyBehavior extends Behavior +{ + // ... + + public function events() + { + return [ + ActiveRecord::EVENT_BEFORE_VALIDATE => 'beforeValidate', + ]; + } + + public function beforeValidate($event) + { + // ... + } +} +``` + + User and IdentityInterface --------------------------