Yii Framework Forum: [Risolto]Return Model->Id If Exist Nel Beforesave() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Risolto]Return Model->Id If Exist Nel Beforesave() model, beforeSave, exist Rate Topic: -----

#1 User is offline   paskuale 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 352
  • Joined: 30-December 11
  • Location:Italy, Bari

Posted 03 January 2013 - 11:25 PM

Salve, sono davanti a questo scenario:
> registrazione utente
> se (utente->cognome && ->nome && ->codFiscale) esiste già non devo duplicare.
> allo stesso tempo, devo scrivere l'id (dell'utente nuovo o esistente) in un altro model


avevo pensato al beforeSave() del model 'Utente' ma non ho la minima idea di come farmi ritornare l'id (che sia create o update)

tnx :)
0

#2 User is offline   paskuale 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 352
  • Joined: 30-December 11
  • Location:Italy, Bari

Posted 04 January 2013 - 12:54 AM

Le notti portan consiglio ::) mi auto-replico

public function actionCreate() {
        $model = new Utente;
        // Uncomment the following line if AJAX validation is needed
        //$this->performAjaxValidation($model);

        if (isset($_POST['Utente'])) 
            {
                $EsisteGia = $model->checkDuplicate(
                        $_POST['Utente']['cognome'],
                        $_POST['Utente']['nome'],
                        $_POST['Utente']['cf']);
                
                        if($EsisteGia){
                            $model = $this->loadModel($EsisteGia->id);
                        }
                        
                        
                $model->attributes = $_POST['Utente'];
                if ($model->save()){//.......

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users