yii\db\BaseActiveRecord::updateCounters PHP Method

updateCounters() public method

Note that this method differs from BaseActiveRecord::updateAllCounters in that it only saves counters for the current AR object. An example usage is as follows: php $post = Post::findOne($id); $post->updateCounters(['view_count' => 1]);
See also: updateAllCounters()
public updateCounters ( array $counters ) : boolean
$counters array the counters to be updated (attribute name => increment value) Use negative values if you want to decrement the counters.
return boolean whether the saving is successful
    public function updateCounters($counters)
    {
        if (static::updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) {
            foreach ($counters as $name => $value) {
                if (!isset($this->_attributes[$name])) {
                    $this->_attributes[$name] = $value;
                } else {
                    $this->_attributes[$name] += $value;
                }
                $this->_oldAttributes[$name] = $this->_attributes[$name];
            }
            return true;
        } else {
            return false;
        }
    }