/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's BasePeer::TYPE_PHPNAME * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = CategoriagastoPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setIdcategoriagasto($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setCategoriagastoNombre($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCategoriagastoDescripcion($arr[$keys[2]]); } }
public function editarAction() { //ID ENTIDAD $id = $this->params()->fromRoute('id'); $request = $this->getRequest(); if ($request->isPost()) { $post_data = $request->getPost(); //INSTANCIAMOS NUESTRA ENTIDAD $entity = \CategoriagastoQuery::create()->findPk($id); //SETIAMOS NUESTROS DATOS CON EXCEPCIONES foreach ($post_data as $key => $value) { if (\CategoriagastoPeer::getTableMap()->hasColumn($key)) { $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME); } } $entity->save(); //Agregamos un mensaje $this->flashMessenger()->addSuccessMessage('Registro guardado exitosamente!'); //REDIRECCIONAMOS A LA ENTIDAD QUE ACABAMOS DE CREAR return $this->redirect()->toRoute('admin/catalogo/catergoria-gastos', array('action' => 'editar', 'id' => $entity->getIdcategoriagasto())); } $exist = \CategoriagastoQuery::create()->filterByIdcategoriagasto($id)->exists(); if ($exist) { $entity = \CategoriagastoQuery::create()->findPk($id); //INSTANCIAMOS NUESTRO FORMULARIO $form = new \Catalogo\Form\CategoriagastosForm(); $form->setData($entity->toArray(\BasePeer::TYPE_FIELDNAME)); //RETORNAMOS A NUESTRA VISTA $view_model = new ViewModel(); $view_model->setTemplate('admin/catalogo/categoriasgastos/editar'); $view_model->setVariables(array('entity' => json_encode($entity->toArray(\BasePeer::TYPE_FIELDNAME)), 'successMessages' => json_encode($this->flashMessenger()->getSuccessMessages()), 'form' => $form)); return $view_model; } else { return $this->redirect()->toRoute('admin/catalogo/gastos', array('action' => 'index')); } }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return Categoriagasto A model object, or null if the key is not found * @throws PropelException */ protected function findPkSimple($key, $con) { $sql = 'SELECT `idcategoriagasto`, `categoriagasto_nombre`, `categoriagasto_descripcion` FROM `categoriagasto` WHERE `idcategoriagasto` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new Categoriagasto(); $obj->hydrate($row); CategoriagastoPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * Selects a collection of Gastofacturacion objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of Gastofacturacion objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(GastofacturacionPeer::DATABASE_NAME); } GastofacturacionPeer::addSelectColumns($criteria); $startcol2 = GastofacturacionPeer::NUM_HYDRATE_COLUMNS; CategoriagastoPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + CategoriagastoPeer::NUM_HYDRATE_COLUMNS; $criteria->addJoin(GastofacturacionPeer::IDCATEGORIAGASTO, CategoriagastoPeer::IDCATEGORIAGASTO, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = GastofacturacionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = GastofacturacionPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = GastofacturacionPeer::getOMClass(); $obj1 = new $cls(); $obj1->hydrate($row); GastofacturacionPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Categoriagasto rows $key2 = CategoriagastoPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = CategoriagastoPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = CategoriagastoPeer::getOMClass(); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); CategoriagastoPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (Gastofacturacion) to the collection in $obj2 (Categoriagasto) $obj2->addGastofacturacion($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @return Categoriagasto[] * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(CategoriagastoPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(CategoriagastoPeer::DATABASE_NAME); $criteria->add(CategoriagastoPeer::IDCATEGORIAGASTO, $pks, Criteria::IN); $objs = CategoriagastoPeer::doSelect($criteria, $con); } return $objs; }