/** * Returns a new UdmQuery object. * * @param string $modelAlias The alias of a model in the query * @param UdmQuery|Criteria $criteria Optional Criteria to build the query from * * @return UdmQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof UdmQuery) { return $criteria; } $query = new UdmQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(UdmPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = UdmQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
public function eliminarAction() { //Cachamos el valor desde nuestro params $id = (int) $this->params()->fromRoute('id'); //Verificamos que el Id udm que se quiere eliminar exista if (!\UdmQuery::create()->filterByIdudm($id)->exists()) { $id = 0; } //Si es incorrecto redireccionavos al action nuevo if (!$id) { return $this->redirect()->toRoute('udm'); } //Instanciamos nuestro udm $udm = UdmQuery::create()->findPk($id); $udm->delete(); //Agregamos un mensaje $this->flashMessenger()->addMessage('Unidad de medida eliminada exitosamente!'); //Redireccionamos a nuestro list return $this->redirect()->toRoute('udm'); }