PHP code example of ivankff / yii2-log-after-save

1. Go to this page and download the library: Download ivankff/yii2-log-after-save 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/ */

    

ivankff / yii2-log-after-save example snippets


/**
 * @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);
}