After numerous different attempts to get this to work I need to come ask for help.
The goal is to have a transaction complete before a view file is rendered per the given controller. If the transaction fails I want the user to be redirected to the page they came from. I know it looks like I am only doing a single insert and would not require a transaction but this is way scaled back so I can test the concept then roll everything back in.
How would I roll this code for the transaction into the controller code for the view action?
View file that I only want rendered upon successful completion of the transaction.
public function actionView($id) {
$this->render('view', array(
'model' => $this->loadModel($id, 'Item'),
));
}
EDIT: Change of approach needed?
Ok now that I have a working transaction I question my initial approach to this problem. Since I am using a CJuiButton to link to this view that I was trying to put transaction into, would it be a better approach to have the button kickoff the transaction through onclick instead? I say this because right now every time I reload the view (with transaction rolled in) a new db entry is created. Any thoughts?
Gustavo thanks for the quick response. When I add my transaction code along with your suggestion into my actionView function the view no longer displays (error 400/invalid request) and nothing occurs with my transaction (no input into db). I know I am missing the concept here.
if the transaction is successful and redirecting if it is not. But again I was unsuccessful and doing just that too, hence my original question. Unless your approach will prevent the execution of the transaction on a page reload which adds an additional row in the db.
Ok now that I have a working transaction I question my initial approach to this problem. Since I am using a CJuiButton to link to this view that I was trying to put transaction into, would it be a better approach to have the button kickoff the transaction through onclick instead? I say this because right now every time I reload the view (with transaction rolled in) a new db entry is created. Any thoughts?