framework/db/BaseActiveRecord.php
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;
        }

        return false;
    }
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;
        }

        return false;
    }
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 ; } return false ; }
Updates one or several counter columns for the current AR object.
Note that this method differs from [[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]);
```

@param array $counters the counters to be updated (attribute name => increment value)
Use negative values if you want to decrement the counters.
@return bool whether the saving is successful
@see updateAllCounters()
Updates one or several counter columns for the current AR object . Note that this method differs from [[ updateAllCounters () ]] in that it only saves counters for the current AR object .