Cake\Database\Query::set PHP Method

set() public method

### Examples Passing a string: $query->update('articles')->set('title', 'The Title'); Passing an array: $query->update('articles')->set(['title' => 'The Title'], ['title' => 'string']); Passing a callable: $query->update('articles')->set(function ($exp) { return $exp->eq('title', 'The title', 'string'); });
public set ( string | array | callable | Cake\Database\Expression\QueryExpression $key, mixed $value = null, array $types = [] )
$key string | array | callable | Cake\Database\Expression\QueryExpression The column name or array of keys + values to set. This can also be a QueryExpression containing a SQL fragment. It can also be a callable, that is required to return an expression object.
$value mixed The value to update $key to. Can be null if $key is an array or QueryExpression. When $key is an array, this parameter will be used as $types instead.
$types array The column types to treat data as.
    public function set($key, $value = null, $types = [])
    {
        if (empty($this->_parts['set'])) {
            $this->_parts['set'] = $this->newExpr()->tieWith(',');
        }
        if ($this->_parts['set']->isCallable($key)) {
            $exp = $this->newExpr()->tieWith(',');
            $this->_parts['set']->add($key($exp));
            return $this;
        }
        if (is_array($key) || $key instanceof ExpressionInterface) {
            $types = (array) $value;
            $this->_parts['set']->add($key, $types);
            return $this;
        }
        if (is_string($types) && is_string($key)) {
            $types = [$key => $types];
        }
        $this->_parts['set']->eq($key, $value, $types);
        return $this;
    }