Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 Model set() returns error
#5

(03-28-2024, 12:58 AM)kenjis Wrote: As you see the first parameter of set() method is:

PHP Code:
@param array|object|string              $key    Field name, or an array of field/value pairs 

So you cannot pass an entity to the set() method.

Shouldn't it be the same as BaseBuilder set() function ?

PHP Code:
/**
    * Allows key/value pairs to be set for insert(), update() or replace().
    *
    * @param array|object|string $key    Field name, or an array of field/value pairs
    * @param mixed              $value  Field value, if $key is a single field
    * @param bool|null          $escape Whether to escape values
    *
    * @return $this
    */
    public function set($key$value '', ?bool $escape null)
    {
        $key $this->objectToArray($key); // Object to Array?

        if (! is_array($key)) {
            $key = [$key => $value];
        }

        $escape is_bool($escape) ? $escape $this->db->protectIdentifiers;

        foreach ($key as $k => $v) {
            if ($escape) {
                $bind $this->setBind($k$v$escape);

                $this->QBSet[$this->db->protectIdentifiers($kfalse)] = ":{$bind}:";
            } else {
                $this->QBSet[$this->db->protectIdentifiers($kfalse)] = $v;
            }
        }

        return $this;
    
Reply


Messages In This Thread
RE: Codeigniter 4 Model set() returns error - by MZahov - 03-28-2024, 01:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB