lithium\data\Entity::increment()

public method

Safely (atomically) increments the value of the specified field by an arbitrary value. Defaults to 1 if no value is specified. Throws an exception if the specified field is non-numeric.

Parameters

  • string $field

    The name of the field to be incremented.

  • integer|string $value

    The value to increment the field by. Defaults to 1 if this parameter is not specified.

Returns

integer

Returns the current value of $field, based on the value retrieved from the data source when the entity was loaded, plus any increments applied. Note that it may not reflect the most current value in the persistent backend data source.

Source

	public function increment($field, $value = 1) {
		if (!isset($this->_updated[$field])) {
			$this->_updated[$field] = 0;
		} elseif (!is_numeric($this->_updated[$field])) {
			throw new UnexpectedValueException("Field `'{$field}'` cannot be incremented.");
		}

		if (!isset($this->_increment[$field])) {
			$this->_increment[$field] = 0;
		}
		$this->_increment[$field] += $value;

		return $this->_updated[$field] += $value;
	}