Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionCreate()
- {
- $model1=new PessoaJuridica;
- $model2=new Usuario;
- // Uncomment the following line if AJAX validation is needed
- // $this->performAjaxValidation($model);
- if(isset($_POST['PessoaJuridica'],$_POST['Usuario']))
- {
- $model1->attributes=$_POST['PessoaJuridica'];
- $model2->attributes=$_POST['Usuario'];
- $valid=$model1->validate();
- $valid=$model2->validate() && $valid;
- if($valid){
- $trans = Yii::app()->db->beginTransaction();
- try {
- $model2->save(false);
- //$aux = $model2->findByPk('67');
- $model1->idUsuario = $model2->primaryKey;
- $model1->save(false);
- $trans->commit();
- if (Yii::app()->user->isGuest){
- $identity=new UserIdentity($model2->email,$model2->senha);
- $identity->authenticate();
- Yii::app()->user->login($identity);
- $this->redirect('index.php?r='.Yii::app()->user->returnUrl);
- //$this->redirect(array('/site/logout'));
- }else if (Yii::app()->user->getState('perfil') == '3'){
- $this->redirect(array('view','id'=>$model1->idPessoaJuridica));
- }
- } catch (Exception $e) {
- $trans->rollback();
- throw $e;
- }
- }
- }
- $this->render('create',array(
- 'model1'=>$model1,
- 'model2'=>$model2,
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement