Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86|Last
Lessons:-Models

A common workaround for this implementation issue is to copy virtualFields from one model to
another at runtime when you need to access them:
$this->virtualFields[’name’] = $this->Author->virtualFields[’name’];
or:
$this->virtualFields += $this->Author->virtualFields;
Transactions
To perform a transaction, a model’s tables must be of a type that supports transactions.
All transaction methods must be performed on a model’s DataSource object. To get a model’s DataSource
from within the model, use:
$dataSource = $this->getDataSource();
You can then use the data source to start, commit, or roll back transactions.
$dataSource->begin();
// Perform some tasks
if (/*all’s well*/) {
$dataSource->commit();
} else {
$dataSource->rollback();
}
Nested Transactions
It is possible to start a transaction several times using the Datasource::begin() method. The transaction
will finish only when the number of commit and rollback match with begin’s.
$dataSource->begin();
// Perform some tasks
$dataSource->begin();
// More few tasks
if (/*latest task ok*/) {
$dataSource->commit();
} else {
$dataSource->rollback();
// Change something in main task
}
$dataSource->commit();
This will perform the real nested transaction if your database supports it and it is enabled in the datasource.
The methods will always return true when in transaction mode and the nested is not supported or disabled.
If you want to use multiple begin’s but not use the nested transaction from database, disable it using
$dataSource->useNestedTransactions = false;. It will use only the global transaction.

 
 
 

osdyui

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)