Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1.     public function actionCreate()
  2.     {
  3.         $model1=new PessoaJuridica;
  4.         $model2=new Usuario;
  5.  
  6.         // Uncomment the following line if AJAX validation is needed
  7.         // $this->performAjaxValidation($model);           
  8.  
  9.         if(isset($_POST['PessoaJuridica'],$_POST['Usuario']))
  10.         {
  11.             $model1->attributes=$_POST['PessoaJuridica'];
  12.             $model2->attributes=$_POST['Usuario'];
  13.            
  14.             $valid=$model1->validate();
  15.             $valid=$model2->validate() && $valid;
  16.            
  17.             if($valid){                        
  18.  
  19.                 $trans = Yii::app()->db->beginTransaction();
  20.                 try {
  21.                    
  22.                     $model2->save(false);
  23.                     //$aux = $model2->findByPk('67');                          
  24.                     $model1->idUsuario = $model2->primaryKey;                  
  25.                     $model1->save(false);  
  26.  
  27.                     $trans->commit();
  28.                    
  29.                     if (Yii::app()->user->isGuest){    
  30.                         $identity=new UserIdentity($model2->email,$model2->senha);
  31.                         $identity->authenticate(); 
  32.                         Yii::app()->user->login($identity);    
  33.                         $this->redirect('index.php?r='.Yii::app()->user->returnUrl);
  34.                        
  35.                         //$this->redirect(array('/site/logout'));
  36.                     }else if (Yii::app()->user->getState('perfil') == '3'){
  37.                         $this->redirect(array('view','id'=>$model1->idPessoaJuridica));
  38.                     }
  39.                                        
  40.                 } catch (Exception $e) {
  41.                     $trans->rollback();
  42.                     throw $e;
  43.                                    
  44.                 }              
  45.                                
  46.             }                  
  47.                
  48.         }
  49.  
  50.         $this->render('create',array(
  51.             'model1'=>$model1,
  52.             'model2'=>$model2,
  53.         ));
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement