Cake\Controller\Component\PaginatorComponent::_prefix PHP Method

_prefix() protected method

Prefixes the field with the table alias if possible.
protected _prefix ( Cake\Datasource\RepositoryInterface $object, array $order, boolean $whitelisted = false ) : array
$object Cake\Datasource\RepositoryInterface Repository object.
$order array Order array.
$whitelisted boolean Whether or not the field was whitelisted
return array Final order array.
    protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false)
    {
        $tableAlias = $object->alias();
        $tableOrder = [];
        foreach ($order as $key => $value) {
            if (is_numeric($key)) {
                $tableOrder[] = $value;
                continue;
            }
            $field = $key;
            $alias = $tableAlias;
            if (strpos($key, '.') !== false) {
                list($alias, $field) = explode('.', $key);
            }
            $correctAlias = $tableAlias === $alias;
            if ($correctAlias && $whitelisted) {
                // Disambiguate fields in schema. As id is quite common.
                if ($object->hasField($field)) {
                    $field = $alias . '.' . $field;
                }
                $tableOrder[$field] = $value;
            } elseif ($correctAlias && $object->hasField($field)) {
                $tableOrder[$tableAlias . '.' . $field] = $value;
            } elseif (!$correctAlias && $whitelisted) {
                $tableOrder[$alias . '.' . $field] = $value;
            }
        }
        return $tableOrder;
    }