I currently have a working transaction within my update action.
I am trying to run this transaction, if and only if $model->Status turns from ‘P’ to ‘A’ but not sure how to go about this. Below is my non working attempt. Anyone have any ideas?
public function actionUpdate($id) {
$model = $this->loadModel($id, 'Model');
if (isset($_POST['Model'])) {
$model->setAttributes($_POST['Model']);
if (isset($_POST['Status']) && $_POST['Status']=='A') //execute transaction only if updated 'Status' is set to 'A'
{ $connection = yii::app()->db;
$transaction=$connection->beginTransaction();
try
{
$model->save();
$connection = yii::app()->db;
$sql1 = transaction...
$sql2 = transaction...
$command->execute();
$transaction->commit();
$this->redirect(array('/../..'));
}
catch(Exception $e)
{
$transaction->rollBack();
$this->redirect(array('..'));
}
}
else $model->save();
$this->redirect(array('/../..'));
}
$this->render('update', array(
'model' => $model,
));
}