Nette\Database\Table\ActiveRow::update PHP Метод

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

Updates row.
public update ( $data ) : boolean
Результат boolean
    public function update($data)
    {
        if ($data instanceof \Traversable) {
            $data = iterator_to_array($data);
        }
        $primary = $this->getPrimary();
        if (!is_array($primary)) {
            $primary = [$this->table->getPrimary() => $primary];
        }
        $selection = $this->table->createSelectionInstance()->wherePrimary($primary);
        if ($selection->update($data)) {
            if ($tmp = array_intersect_key($data, $primary)) {
                $selection = $this->table->createSelectionInstance()->wherePrimary($tmp + $primary);
            }
            $selection->select('*');
            if (($row = $selection->fetch()) === FALSE) {
                throw new Nette\InvalidStateException('Database refetch failed; row does not exist!');
            }
            $this->data = $row->data;
            return TRUE;
        } else {
            return FALSE;
        }
    }

Usage Example

Пример #1
0
 public function submitFormGeneratePassword(Form $form)
 {
     $values = $form->getValues();
     $this->userRow->update(array('password' => md5($values['password']), 'hash' => NULL));
     $this->flashMessage($this->translator->translate('admin.sign.passwordChanged'));
     $this->redirect('default');
 }
All Usage Examples Of Nette\Database\Table\ActiveRow::update