Cake\Database\Query::select PHP Метод

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

If an array is passed, keys will be used to alias fields using the value as the real field to be aliased. It is possible to alias strings, Expression objects or even other Query objects. If a callable function is passed, the returning array of the function will be used as the list of fields. By default this function will append any passed argument to the list of fields to be selected, unless the second argument is set to true. ### Examples: $query->select(['id', 'title']); // Produces SELECT id, title $query->select(['author' => 'author_id']); // Appends author: SELECT id, title, author_id as author $query->select('id', true); // Resets the list: SELECT id $query->select(['total' => $countQuery]); // SELECT id, (SELECT ...) AS total $query->select(function ($query) { return ['article_id', 'total' => $query->count('*')]; }) By default no fields are selected, if you have an instance of Cake\ORM\Query and try to append fields you should also call Cake\ORM\Query::autoFields() to select the default fields from the table.
public select ( array | Cake\Database\ExpressionInterface | string | callable $fields = [], boolean $overwrite = false )
$fields array | Cake\Database\ExpressionInterface | string | callable fields to be added to the list.
$overwrite boolean whether to reset fields with passed list or not
    public function select($fields = [], $overwrite = false)
    {
        if (!is_string($fields) && is_callable($fields)) {
            $fields = $fields($this);
        }
        if (!is_array($fields)) {
            $fields = [$fields];
        }
        if ($overwrite) {
            $this->_parts['select'] = $fields;
        } else {
            $this->_parts['select'] = array_merge($this->_parts['select'], $fields);
        }
        $this->_dirty();
        $this->_type = 'select';
        return $this;
    }

Usage Example

Пример #1
4
 public function findProductId(Query $query, array $options)
 {
     $result = $query->select(['id'])->where(['article_uid' => $options['uid']])->first();
     if ($result == null) {
         return null;
     } else {
         return $result->id;
     }
 }
All Usage Examples Of Cake\Database\Query::select