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

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

Returns primary key value.
public getPrimary ( $need = TRUE ) : mixed
Результат mixed possible int, string, array, object (Nette\Utils\DateTime)
    public function getPrimary($need = TRUE)
    {
        $primary = $this->table->getPrimary($need);
        if ($primary === NULL) {
            return NULL;
        } elseif (!is_array($primary)) {
            if (isset($this->data[$primary])) {
                return $this->data[$primary];
            } elseif ($need) {
                throw new Nette\InvalidStateException("Row does not contain primary {$primary} column data.");
            } else {
                return NULL;
            }
        } else {
            $primaryVal = [];
            foreach ($primary as $key) {
                if (!isset($this->data[$key])) {
                    if ($need) {
                        throw new Nette\InvalidStateException("Row does not contain primary {$key} column data.");
                    } else {
                        return NULL;
                    }
                }
                $primaryVal[$key] = $this->data[$key];
            }
            return $primaryVal;
        }
    }

Usage Example

Пример #1
0
 /**
  * Returns primary key value.
  *
  * @param $need bool
  * @return mixed possible int, string, array, object (Nette\Utils\DateTime)
  */
 public function getPrimary($need = TRUE)
 {
     return $this->activeRow->getPrimary($need);
 }