mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Fixes #4845
This commit is contained in:
@ -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()]].
|
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
|
There are many other changes and enhancements to Active Record. Please refer to
|
||||||
the [Active Record](db-active-record.md) section for more details.
|
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
|
User and IdentityInterface
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user