ManaPHP\Mvc\Model\QueryBuilder::orderBy PHP Метод

orderBy() публичный Метод

$builder->orderBy('Robots.name'); $builder->orderBy(array('1', 'Robots.name'));
public orderBy ( string $orderBy ) : static
$orderBy string
Результат static
    public function orderBy($orderBy)
    {
        if (preg_match('#^[a-z0-9_.\\s]*$#i', $orderBy) === 1) {
            $r = '';
            foreach (explode(',', $orderBy) as $item) {
                $parts = explode(' ', trim($item));
                if (count($parts) === 1) {
                    $by = trim($parts[0]);
                    $type = 'ASC';
                } elseif (count($parts) === 2) {
                    $by = trim($parts[0]);
                    $type = strtoupper($parts[1]);
                } else {
                    $r = $orderBy;
                    break;
                }
                if (preg_match('#^[a-z_][a-z0-9_.]*#i', $by) === 1) {
                    $r .= preg_replace('#[a-z_][a-z0-9_]*#i', '[\\0]', $by) . ' ' . $type . ', ';
                }
            }
            $this->_order = substr($r, 0, -2);
        } else {
            $this->_order = $orderBy;
        }
        return $this;
    }