PHP code example of yii2tech / behavior-trait
1. Go to this page and download the library: Download yii2tech/behavior-trait library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yii2tech / behavior-trait example snippets
use yii\db\ActiveRecord;
use yii2tech\behaviortrait\BehaviorTrait;
class User extends ActiveRecord
{
use BehaviorTrait; // add `BehaviorTrait` allowing to use inline event handlers
use EncryptPasswordTrait; // add trait, which introduce inline event handler
// ...
}
trait EncryptPasswordTrait
{
public function beforeInsertHandlerEncryptPassword(Event $event)
{
if (!empty($this->newPassword)) {
$this->password = sha1($this->newPassword);
}
}
}