ivankff/yii2-log-after-save

yii2 save logs after AR saving

Installs: 49

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

0.1.1 2020-06-26 14:04 UTC

This package is auto-updated.

Last update: 2024-09-26 22:52:39 UTC


README

ActiveRecord

/**
 * @param int $statusId
 * @param string|null $comment
 */
public function setStatus($statusId, $comment = null)
{
    $this->setAttribute('status_id', $statusId);
    $this->_addLog(new StatusLog(['order_id' => $this->id, 'status_id' => $statusId, 'comment' => $comment]));
}

/**
 * @param ActiveRecord $log
 */
protected function _addLog(ActiveRecord $log)
{
    /** @var LogAfterSaveBehavior $behavior */
    $behavior = $this->getBehavior(LogAfterSaveBehavior::NAME);

    if (! $behavior)
        $behavior = $this->attachBehavior(LogAfterSaveBehavior::NAME, LogAfterSaveBehavior::class);

    $behavior->addLog($log);
}