1
votes

I've a form class called PersonaForm.class.php and this is the code inside this class:

class PersonaForm extends BasePersonaForm {

    private $enfermedades_noseleccionadas = array();
    private $antecedentes_noseleccionados = array();
    private $adicciones_noseleccionadas = array();
    private $alteraciones_noseleccionadas = array();
    private $intolerancias_noseleccionadas = array();

    public function configure() {
        $this->widgetSchema['nombres'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Nombres', 'class' => 'span4', 'required' => 'required'));
        $this->widgetSchema['apellidos'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Apellidos', 'class' => 'span4', 'required' => 'required'));
        $this->widgetSchema['edad'] = new sfWidgetFormInputText(array(), array('class' => 'span1'));
        $this->widgetSchema['estatura'] = new sfWidgetFormInputText(array(), array('class' => 'span1'));
        $this->widgetSchema['lugar_nacimiento'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Lugar de Nacimiento', 'class' => 'span4'));
        $this->widgetSchema['urbanizacion_sector'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Urbanización/Sector', 'class' => 'span4'));
        $this->widgetSchema['calle_avenida'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Calle/Avenida', 'class' => 'span4'));
        $this->widgetSchema['edificio_casa'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Edificio/Casa Nro.', 'class' => 'span4'));
        $this->widgetSchema['piso'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Piso', 'class' => 'span4'));
        $this->widgetSchema['apto'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Apartamento', 'class' => 'span4'));
        $this->widgetSchema['zona_postal'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Zona Postal', 'class' => 'span4'));
        $this->widgetSchema['profesion'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Profesión', 'class' => 'span4'));
        $this->widgetSchema['ocupacion'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Ocupación', 'class' => 'span4'));
        $this->widgetSchema['telefono_fijo'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Teléfono Fijo', 'class' => 'span4'));
        $this->widgetSchema['celular'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Celular', 'class' => 'span4'));
        $this->widgetSchema['correo_electronico'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Correo Electrónico', 'class' => 'span4'));
        $this->widgetSchema['empresa'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Empresa', 'class' => 'span4'));
        $this->widgetSchema['urbanizacion_empresa'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Urbanización Empresa', 'class' => 'span4'));
        $this->widgetSchema['telefono_oficina'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Teléfono Oficina', 'class' => 'span4'));
        $this->widgetSchema['fax_oficina'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Fax Oficina', 'class' => 'span4'));
        $this->widgetSchema['persona_recomienda'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Persona que lo recomendó', 'class' => 'span4'));

        $this->widgetSchema['estado_civil'] = new sfWidgetFormSelectRadio(array('choices' => array('d' => 'Divorciado', 'c' => 'Casado', 's' => 'Soltero', 'co' => 'Concubinato'), 'formatter' => array($this, 'RadioFormatterCallback')));
        $this->widgetSchema['sexo'] = new sfWidgetFormSelectRadio(array('choices' => array('m' => 'Hombre', 'f' => 'Mujer'), 'formatter' => array($this, 'RadioFormatterCallback')));

        $this->widgetSchema['estado_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model' => 'Estado',
            'add_empty' => 'Seleccione estado',
            'ajax' => true
        ));

        $this->widgetSchema['municipio_id'] = new sfWidgetFormDoctrineDependentSelect(array(
            'model' => 'Municipio',
            'depends' => 'Estado',
            'add_empty' => 'Seleccione municipio',
            'ajax' => true,
            'order_by' => array('nombre', 'asc')
        ));

        $this->widgetSchema['fecha_nacimiento'] = new sfWidgetFormDateTime(array('date' => array('format' => '%day%-%month%-%year%'), 'with_time' => false));

        $this->validatorSchema['estado_id'] = new sfValidatorDoctrineChoice(array('model' => 'Estado'));
        $this->validatorSchema['municipio_id'] = new sfValidatorDoctrineChoice(array('model' => 'Municipio'));
        $this->validatorSchema['correo_electronico'] = new sfValidatorEmail(array('required' => true), array('invalid' => 'La dirección de correo no es válida'));


        $historia_clinica = new Hclinica();
        $historia_clinica->setPersona($this->getObject());
        $this->embedForm('historia_clinica', new HclinicaForm($historia_clinica));

        $antecedentes = Doctrine::getTable('Antecedentes')->findAll();
        foreach ($antecedentes as $antecedente) {
            $personaHasAntecedentes = new PersonaHasAntecedentes();
            $personaHasAntecedentes->setAntecedentes($antecedente);
            $personaHasAntecedentes->setPersona($this->getObject());

            $this->embedForm('antecedente_' . $antecedente->getId(), new PersonaHasAntecedentesForm($personaHasAntecedentes));
        }

        $adicciones = Doctrine::getTable('Adicciones')->findAll();
        foreach ($adicciones as $adiccion) {
            $personaHasAdicciones = new PersonaHasAdicciones();
            $personaHasAdicciones->setAdicciones($adiccion);
            $personaHasAdicciones->setPersona($this->getObject());

            $this->embedForm('adiccion_' . $adiccion->getId(), new PersonaHasAdiccionesForm($personaHasAdicciones));
        }

        $intolerancias = Doctrine::getTable('Intolerancias')->findAll();
        foreach ($intolerancias as $intolerancia) {
            $personaHasIntolerancias = new PersonaHasIntolerancias();
            $personaHasIntolerancias->setIntolerancias($intolerancia);
            $personaHasIntolerancias->setPersona($this->getObject());

            $this->embedForm('intolerancia_' . $intolerancia->getId(), new PersonaHasIntoleranciasForm($personaHasIntolerancias));
        }

        $enfermedades = Doctrine::getTable('Enfermedades')->findAll();
        foreach ($enfermedades as $enfermedad) {
            $personaHasEnfermedades = new PersonaHasEnfermedades();
            $personaHasEnfermedades->setEnfermedades($enfermedad);
            $personaHasEnfermedades->setPersona($this->getObject());

            $this->embedForm('enfermedad_' . $enfermedad->getId(), new PersonaHasEnfermedadesForm($personaHasEnfermedades));
        }

        $alteraciones = Doctrine::getTable('Alteraciones')->findAll();
        foreach ($alteraciones as $alteracion) {
            $personaHasAlteraciones = new PersonaHasAlteraciones();
            $personaHasAlteraciones->setAlteraciones($alteracion);
            $personaHasAlteraciones->setPersona($this->getObject());

            $this->embedForm('alteracion_' . $alteracion->getId(), new PersonaHasAlteracionesForm($personaHasAlteraciones));
        }
    }

    public function doBind(array $values) {
        $alteraciones = Doctrine::getTable('Alteraciones')->findAll();
        foreach ($alteraciones as $alteracion) {
            if (empty($values['alteracion_' . $alteracion->getId()]['selected'])) {
                $this->alteraciones_noseleccionadas[] = $alteracion->getId();
            }
        }

        $adicciones = Doctrine::getTable('Adicciones')->findAll();
        foreach ($adicciones as $adiccion) {
            if (empty($values['adiccion_' . $adiccion->getId()]['selected'])) {
                $this->adicciones_noseleccionadas[] = $adiccion->getId();
            }
        }

        $intolerancias = Doctrine::getTable('Intolerancias')->findAll();
        foreach ($intolerancias as $intolerancia) {
            if (empty($values['intolerancia_' . $intolerancia->getId()]['selected'])) {
                $this->intolerancias_noseleccionadas[] = $intolerancia->getId();
            }
        }

        $enfermedades = Doctrine::getTable('Enfermedades')->findAll();
        foreach ($enfermedades as $enfermedad) {
            if (empty($values['enfermedad_' . $enfermedad->getId()]['selected'])) {
                $this->enfermedades_noseleccionadas[] = $enfermedad->getId();
            }
        }
        return parent::doBind($values);
    }

    //modificar la funcion doSave
    public function doSave($con = null) {
        if (!$this->isNew()) {
            foreach ($this->intolerancias_noseleccionadas as $intolerancia_id) {
                unset($this->embeddedForms["intolerancia_" . $intolerancia_id]);
                Doctrine::getTable('PersonaHasIntolerancias')->createQuery()->delete()->where("id_persona = ? and id_intolerancias = ?", array($this->getObject()->getId(), $intolerancia_id))->execute();
            }

            foreach ($this->adicciones_noseleccionadas as $adiccion_id) {
                unset($this->embeddedForms["adiccion_" . $adiccion_id]);
                Doctrine::getTable('PersonaHasAdicciones')->createQuery()->delete()->where("id_persona = ? and id_adiciones = ?", array($this->getObject()->getId(), $adiccion_id))->execute();
            }

            foreach ($this->alteraciones_noseleccionadasas as $alteracion_id) {
                unset($this->embeddedForms["alteracion_" . $alteracion_id]);
                Doctrine::getTable('PersonaHasAlteraciones')->createQuery()->delete()->where("id_persona = ? and id_alteraciones = ?", array($this->getObject()->getId(), $alteracion_id))->execute();
            }

            foreach ($this->enfermedades_noseleccionadas as $enfermedad_id) {
                unset($this->embeddedForms["enfermedad_" . $enfermedad_id]);
                Doctrine::getTable('PersonaHasEnfermedades')->createQuery()->delete()->where("id_persona = ? and id_enfermedades = ?", array($this->getObject()->getId(), $enfermedad_id))->execute();
            }
        }
    }

    public function RadioFormatterCallback($widget, $inputs) {
        $rows = array();
        foreach ($inputs as $input) {
            $rows[] = $widget->renderContentTag('label', $input['input'] . $widget->getOption('separator') . $input['label'], array('class' => 'radio inline'));
        }

        return !$rows ? '' : implode($widget->getOption('separator'), $rows);
    }
}

And another form class called HclinicaForm.class.php with this code:

class HclinicaForm extends BaseHclinicaForm {

    public function configure() {
        $this->widgetSchema['medicamentos'] = new sfWidgetFormSelectRadio(array('choices' => array('n' => 'No', 's' => 'Sí'), 'formatter' => array($this, 'RadioFormatterCallback')));
        $this->widgetSchema['motivo_consulta'] = new sfWidgetFormSelectRadio(array('choices' => array('c' => 'Celulitis', 's' => 'Sobrepeso', 'f' => 'Flacidez', 'o' => 'Otro'), 'formatter' => array($this, 'RadioFormatterCallback')));

        $this->widgetSchema['padre_vivo'] = new sfWidgetFormSelectRadio(array('choices' => array('s' => 'Sí', 'n' => 'No'), 'formatter' => array($this, 'RadioFormatterCallback')));
        $this->widgetSchema['causa_muerte_padre'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Causa de la muerte', 'class' => 'span3'));

        $this->widgetSchema['madre_vivo'] = new sfWidgetFormSelectRadio(array('choices' => array('s' => 'Sí', 'n' => 'No'), 'formatter' => array($this, 'RadioFormatterCallback')));
        $this->widgetSchema['causa_muerte_madre'] = new sfWidgetFormInputText(array(), array('placeholder' => 'Causa de la muerte', 'class' => 'span3'));

        $this->widgetSchema['recibe_inmunizacion'] = new sfWidgetFormSelectRadio(array('choices' => array('s' => 'Sí', 'n' => 'No'), 'formatter' => array($this, 'RadioFormatterCallback')));

        $this->widgetSchema['operacion_practicadas'] = new sfWidgetFormTextarea(array(), array('placeholder' => 'Escriba las operaciones a las cuales a sido sometido el paciente', 'class' => 'span9', 'rows' => 6));
        $this->widgetSchema['terapias_recibidas'] = new sfWidgetFormTextarea(array(), array('placeholder' => 'Escriba las terapias a las cuales a sido sometido el paciente', 'class' => 'span9', 'rows' => 6));
        $this->widgetSchema['alergias_medicamentes'] = new sfWidgetFormTextarea(array(), array('placeholder' => 'Escriba las alergias a medicamentos del paciente', 'class' => 'span9', 'rows' => 6));

        $this->widgetSchema['edad_primera_menstruacion'] = new sfWidgetFormInput(array(), array('class' => 'span1'));
        $this->widgetSchema['edad_menopausia'] = new sfWidgetFormInput(array(), array('class' => 'span1'));
        $this->widgetSchema['metodo_control_natal'] = new sfWidgetFormInput(array(), array('class' => 'span4'));

        $this->widgetSchema['deporte_practicado'] = new sfWidgetFormInput(array(), array('placeholder' => 'Deporte(s) que practica', 'class' => 'span5'));
        $this->widgetSchema['frecuencia'] = new sfWidgetFormInput(array(), array('placeholder' => 'Frecuencia', 'class' => 'span2'));

        $this->widgetSchema['enfermedad_actual'] = new sfWidgetFormInput(array(), array('placeholder' => 'Enfermedad actual', 'class' => 'span5'));

        $this->widgetSchema['veces_come_x_dia'] = new sfWidgetFormInput(array(), array('placeholder' => 'X', 'class' => 'input-mini'));
        $this->widgetSchema['estados_comida'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Es inapetente', 2 => 'Es normal', 3 => 'Muy apetente')));

        $this->widgetSchema['evacua_x_dia'] = new sfWidgetFormInput(array(), array('placeholder' => 'X', 'class' => 'input-mini'));
        $this->widgetSchema['veces_evacua'] = new sfWidgetFormSelectCheckbox(array('choices' => array('1' => 'Diaria', '2' => 'Interdiaria')));

        $this->widgetSchema['veces_orina_x_dia'] = new sfWidgetFormInput(array(), array('placeholder' => 'X', 'class' => 'input-mini'));
        $this->widgetSchema['cantidad_orina_x_dia'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Poca', 2 => 'Normal', 3 => 'Abundante')));

        $this->widgetSchema['sudoracion'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Escasa', 2 => 'Normal', 3 => 'Abundante')));

        $this->widgetSchema['horas_duerme'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Leve', 2 => 'Normal', 3 => 'Profundo')));

        $this->widgetSchema['menstruacion'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Regular', 2 => 'Irregular')));

        $this->widgetSchema['flujo'] = new sfWidgetFormSelectCheckbox(array('choices' => array(1 => 'Escaso', 2 => 'Normal', 3 => 'Abundante')));

        // These validators need to be checked because it's failing
        $this->validatorSchema['menstruacion'] = new sfValidatorPass();
        $this->validatorSchema['horas_duerme'] = new sfValidatorPass();
        $this->validatorSchema['veces_evacua'] = new sfValidatorPass();
        $this->validatorSchema['estados_comida'] = new sfValidatorPass();
        $this->validatorSchema['flujo'] = new sfValidatorPass();
        $this->validatorSchema['sudoracion'] = new sfValidatorPass();
        $this->validatorSchema['cantidad_orina_x_dia'] = new sfValidatorPass();
    }

    public function RadioFormatterCallback($widget, $inputs) {
        $rows = array();
        foreach ($inputs as $input) {
            $rows[] = $widget->renderContentTag('label', $input['input'] . $widget->getOption('separator') . $input['label'], array('class' => 'radio inline'));
        }

        return !$rows ? '' : implode($widget->getOption('separator'), $rows);
    }

}

When I send the form no data is saved and I got redirected to http://his.devserver/frontend_dev.php/persona/edit/id/ with this error

404 | Not Found | sfError404Exception Object persona does not exist ().

stack trace
at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/action/sfAction.class.php line 89 ...
  {

    if (!$condition)

    {

      throw new sfError404Exception($this->get404Message($message));

    }

  }


at sfAction->forward404Unless(, 'Object persona does not exist ().')
in SF_ROOT_DIR/apps/frontend/modules/persona/actions/actions.class.php

line 31 ... at personaActions->executeEdit(object('sfWebRequest')) in SF_ROOT_DIR/lib/vendor/symfony/lib/action/sfActions.class.php line 60 ... at sfActions->execute(object('sfWebRequest')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 92 ... at sfExecutionFilter->executeAction(object('personaActions')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 78 ... at sfExecutionFilter->handleAction(object('sfFilterChain'), object('personaActions')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 42 ... at sfExecutionFilter->execute(object('sfFilterChain')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfFilterChain.class.php line 53 ... at sfFilterChain->execute() in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php line 72 ... at sfBasicSecurityFilter->execute(object('sfFilterChain')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfFilterChain.class.php line 53 ... at sfFilterChain->execute() in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php line 33 ... at sfRenderingFilter->execute(object('sfFilterChain')) in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfFilterChain.class.php line 53 ... at sfFilterChain->execute() in SF_ROOT_DIR/lib/vendor/symfony/lib/controller/sfController.class.php line 238 ... at sfController->forward('persona', 'edit') in SF_ROOT_DIR/lib/vendor/symfony/lib/controller/sfFrontWebController.class.php line 48 ... at sfFrontWebController->dispatch() in SF_ROOT_DIR/lib/vendor/symfony/lib/util/sfContext.class.php line 170 ... at sfContext->dispatch() in SF_ROOT_DIR/web/frontend_dev.php line 13 ...

I check the logs and see this:

10 Doctrine_Connection_Statement execute : SELECT p.id AS p_id, p.sexo AS p_sexo, p.nombres AS p_nombres, p.apellidos AS p_apellidos, p.fecha_nacimiento AS p__fecha_nacimiento, p.edad AS p_edad, p.estatura AS p_estatura, p.lugar_nacimiento AS p__lugar_nacimiento, p.estado_civil AS p__estado_civil, p.direccion AS p__direccion, p.urbanizacion_sector AS p__urbanizacion_sector, p.calle_avenida AS p__calle_avenida, p.edificio_casa AS p__edificio_casa, p.piso AS p_piso, p.apto AS p_apto, p.zona_postal AS p__zona_postal, p.profesion AS p_profesion, p.ocupacion AS p_ocupacion, p.telefono_fijo AS p__telefono_fijo, p.celular AS p__celular, p.correo_electronico AS p__correo_electronico, p.empresa AS p__empresa, p.urbanizacion_empresa AS p__urbanizacion_empresa, p.telefono_oficina AS p__telefono_oficina, p.fax_oficina AS p__fax_oficina, p.persona_recomienda AS p__persona_recomienda, p.estado_id AS p__estado_id, p.municipio_id AS p__municipio_id FROM persona p WHERE (p.id = ?) LIMIT 1 - ()

11   sfError404Exception    Object persona does not exist ().

Why it's not saving nothing? Any help or advice?

2

2 Answers

2
votes

Ok, I've found my mistake. I miss to add parent::doSave($con) to my doSave method. For this reason the function wasn't save nothing. Thanks to all, hope the solution help anothers

0
votes

The error message looks clear: you do not have a Persona object class.

See this symfony documentation page to generate the model objects with a command line like this:

$ php symfony doctrine:build --model