Archive for April 8th, 2008

Transaction behavior

April 8, 2008

Sample model - note the $actsAs
To change default settings do:
Download code
var $actsAs = array(’transaction’ => array(’keyName’ => ‘value’ ;) );

Model Class:
Download code <?php
class Order extends AppModel
{
var $name = ‘Order’;
var $actsAs = array(‘transaction’);
var $hasMany = array(‘OrderDetail’);
?>
Controller Class:
Download code <?php
class OrderController extends AppController {
var $name = ‘Order’;
var $uses = array(‘Order’);
function checkout() {
if(!empty($this->data)) {
$this->Order->begin(); // Start [...]

Creating Reusable Elements with requestAction

April 8, 2008

Creating reusable elements with requestAction is very simple. At the end, we can even cache the element using the new feature in 1.2.
Start of with a simple controller.
Controller Class:
Download code <?php
class PostsController extends AppController {
var $name = ‘Posts’;
function index() {
$posts = $this->Post->findAll();
if(isset($this->params['requested'])) {
return $posts;
}
$this->set(‘posts’, $posts);
}
}
?>
So, we created the Posts controller and we gave it an [...]