implements Phalcon\Mvc\Model\Transaction\ManagerInterface, Phalcon\Di\InjectionAwareInterface
A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them.
This class manages the objects that compose a transaction. A transaction produces a unique connection that is passed to every object part of the transaction.
try { use Phalcon\Mvc\Model\Transaction\Manager as TransactionManager; $transactionManager = new TransactionManager(); $transaction = $transactionManager->get(); $robot = new Robots(); $robot->setTransaction($transaction); $robot->name = "WALL·E"; $robot->created_at = date("Y-m-d"); if ($robot->save() === false){ $transaction->rollback("Can't save robot"); } $robotPart = new RobotParts(); $robotPart->setTransaction($transaction); $robotPart->type = "head"; if ($robotPart->save() === false) { $transaction->rollback("Can't save robot part"); } $transaction->commit(); } catch (Phalcon\Mvc\Model\Transaction\Failed $e) { echo "Failed, reason: ", $e->getMessage(); }
Phalcon\Mvc\Model\Transaction\Manager constructor
Sets the dependency injection container
Returns the dependency injection container
Sets the database service used to run the isolated transactions
Returns the database service used to isolate the transaction
Set if the transaction manager must register a shutdown function to clean up pendent transactions
Check if the transaction manager is registering a shutdown function to clean up pendent transactions
Checks whether the manager has an active transaction
Returns a new \Phalcon\Mvc\Model\Transaction or an already created once This method registers a shutdown function to rollback active connections
Create/Returns a new transaction or an existing one
Rollbacks active transactions within the manager
Commits active transactions within the manager
Rollbacks active transactions within the manager Collect will remove the transaction from the manager
Notifies the manager about a rollbacked transaction
Notifies the manager about a committed transaction
Removes transactions from the TransactionManager
Remove all the transactions from the manager
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Transaction_Manager.html