class ProductsController extends PhalconMvcController
{
public function saveAction()
{
//Obtain the TransactionsManager from the services container
$manager = $this->di->getTransactions();
//Or
$manager = $this->transactions;
//Request a transaction
$transaction = $manager->get();
//...
}
}
使用:
//Find a robot by its name
$robot = Robots::findFirst("theName = 'Voltron'");
echo $robot->theName, "
";
//Get robots ordered by type
$robot = Robots::find(array('order' => 'theType DESC'));
foreach ($robots as $robot) {
echo 'Code: ', $robot->code, "
";
}
//Create a robot
$robot = new Robots();
$robot->code = '10101';
$robot->theName = 'Bender';
$robot->theType = 'Industrial';
$robot->theYear = 2999;
$robot->save();