Pages

Sunday, June 26, 2011

Transactions Shortcut in Cakephp

Add the following functions in app/models/AppModel

function begin()
{
$db=&ConnectionManger::getDataSource
$db->begin($this);
$this->useDbConfig;
}

function commit()
{
$db->commit($this);
}

function rollback()
{
$db->rollback($this);
}

Now in you controller
Use
$this->Model->Begin()
$this->Model->commit();
$this->Model->rollback();

No comments:

Post a Comment