We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to redo the save option in phalcon

this is my code ......

$user= new user();
$user->id=$this->request->getPost('id');
$user->name=$this->request->getPost('name');
$save=$user->save();
if($save==False){
$emp= new Employee();
$emp->is=$this->request->getPost('id');
$emp->name=$this->request->getPost('name');
$emp->mdn=$this->request->getPost('mdn');
$emp->save();
}

now sometimes i able to save the data in first table but not able to save the data in second table..in that case i want to redo the save option done in the first table.....how to that...as kept uniqueness validator in the first table if iam trying again its is saying that the data is already present as the data already saved in the table. Please help??



145.0k
Accepted
answer

Use transaction.

transction is not working when i am using alias below is my code.....

                $rel->setTransaction($transaction);
                $rel->emp_id = $user->id;
                $rel->wal_id = $this->request->getPost($type->wallettype_code);  
                $rel->pay_limit=$rel->limits->loading_limit;
                $rel->save();
                if($rel->save()==FALSE){
                $transction->rollback("Sorry");
                }

                but when i  am trying to save.....I got an error stating ::  trying to get a property of an non object....
                Please help