/** * * @param array $data * @throws Exception */ public function gravar(array $data) { try { $this->_modelNotificacao->insert($data); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } }
/** * 保存数据 * @param array $entity 有属性名和所要插入的属性值组成的一维数组或二维数组,如:$parameter = array('shopName'=>'kongfz','userId'=>1) * @param string $table 表名 * @param boolean $isReturnLastInsertId true:获取插入记录自增id,false:不返回插入记录自增id * @param int $dimension 参数$parameter维度 1:插入一条数据,2:插入多条数据 * @return boolean or int */ public function insert(array $entity, $table = '', $isReturnLastInsertId = true, $dimension = 1) { if (is_null($this->db)) { $this->db = \Util\Db\Manager::getInstance($this->dbName); } //如果方法中没传递表名,则向默认表中插入数据 $table = is_string($table) && $table != '' ? $table : $this->defaultTable; $state = $this->db->insert($entity, $table, $dimension); if ($isReturnLastInsertId && $state) { return $this->db->getLastInsertId(); } return $state; }
/** * * @param \Music\Model\Artist $artist * @throws \Exception */ public function saveArtist(Artist $artist) { $data = array('full_name' => $artist->getFullName(), 'year_found' => $artist->getYearFound(), 'origin' => $artist->getOrigin(), 'createdby' => $this->id); $artist_id = (int) $artist->getArtistId(); if ($artist_id == 0) { $this->tableGateway->insert($data); } else { if ($this->getArtist($artist_id)) { //\Zend\Debug\Debug::dump($artist_id); $this->tableGateway->update($data, array('artist_id' => $artist_id)); } else { throw new \Exception('Form id does not exist'); } } }
/** * Insert a row in contact table * @param type $data * @return boolean */ public function insertContactData($data) { try { $this->tableGateway->insert($data); return true; } catch (Exception $e) { return false; } }
/** * Save * * @return integer */ public function save() { if (is_array($this->primaryKey)) { // @todo compound primary keys } if (isset($this->originalData[$this->primaryKey])) { // UPDATE $where = array($this->primaryKey => $this->originalData[$this->primaryKey]); $data = $this->currentData; unset($data[$this->primaryKey]); $rowsAffected = $this->tableGateway->update($data, $where); } else { // INSERT $rowsAffected = $this->tableGateway->insert($this->currentData); $primaryKey = $this->tableGateway->getLastInsertId(); $where = array($this->primaryKey => $primaryKey); } // refresh data $result = $this->tableGateway->select($where); $rowData = $result->current(); $this->populateOriginalData($rowData); return $rowsAffected; }
/** * * @throws Exception */ public function salvar() { $this->validar(); $this->table->insert(array('nmCargo' => $this->getCargo(), 'dsJustificativa' => $this->getJustificativa())); }