lithium\data\Model::key PHP Method

key() public static method

If no values supplied, returns the name of the Model key. If values are supplied, returns the key value.
public static key ( mixed $values = null ) : mixed
$values mixed An array of values or object with values. If `$values` is `null`, the meta `'key'` of the model is returned.
return mixed Key value.
    public static function key($values = null)
    {
        $key = static::meta('key');
        if ($values === null) {
            return $key;
        }
        $self = static::_object();
        $entity = $self->_classes['entity'];
        if (is_object($values) && is_string($key)) {
            return static::_key($key, $values, $entity);
        } elseif ($values instanceof $entity) {
            $values = $values->to('array');
        }
        if (!is_array($values) && !is_array($key)) {
            return array($key => $values);
        }
        $key = (array) $key;
        $result = array();
        foreach ($key as $value) {
            if (!isset($values[$value])) {
                return null;
            }
            $result[$value] = $values[$value];
        }
        return $result;
    }