public function editarAction()
 {
     //ID ENTIDAD
     $id = $this->params()->fromRoute('id');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost();
         //INSTANCIAMOS NUESTRA ENTIDAD
         $entity = \GastofacturacionQuery::create()->findPk($id);
         //SETIAMOS NUESTROS DATOS CON EXCEPCIONES
         foreach ($post_data as $key => $value) {
             if (\GastofacturacionPeer::getTableMap()->hasColumn($key)) {
                 $entity->setByName($key, $value, \BasePeer::TYPE_FIELDNAME);
             }
         }
         //SETIAMOS EL IVA
         $entity->setGastofacturacionIva($post_data['gastofacturacion_iva']);
         $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/gastos', array('action' => 'editar', 'id' => $entity->getIdgastofacturacion()));
     }
     $exist = \GastofacturacionQuery::create()->filterByIdgastofacturacion($id)->exists();
     if ($exist) {
         $entity = \GastofacturacionQuery::create()->findPk($id);
         //LE DAMOS FORMATO A LAS CATEGORIAS DE GASTOS
         $categorias_gastos = \CategoriagastoQuery::create()->find();
         $categorias_gastos_array = array();
         foreach ($categorias_gastos as $categoria_gasto) {
             $idcategoriagasto = $categoria_gasto->getIdcategoriagasto();
             $categorias_gastos_array[$idcategoriagasto] = $categoria_gasto->getCategoriagastoNombre();
         }
         //INSTANCIAMOS NUESTRO FORMULARIO
         $form = new \Catalogo\Form\GastoForm($categorias_gastos_array);
         $form->setData($entity->toArray(\BasePeer::TYPE_FIELDNAME));
         //RETORNAMOS A NUESTRA VISTA
         $view_model = new ViewModel();
         $view_model->setTemplate('admin/catalogo/gastos/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'));
     }
 }