Reputation: 317
my controller: productsController.php
public function buyProduct(){
// some functionaliy and returns
$data = array(
'user_id' => $this->Auth->user('id'),
'product_id' => 11,
'trans_id' => 12,
'auth_code' => 13
);
App::uses('Order', 'Model');
$this->Order->create();
$this->Order->save($data);
Now i want to save this $data to table name order how can i do this
}
Upvotes: 0
Views: 288
Reputation: 1413
In CakePhp 2.6.11 I use this:
class productsController extends AppController {
public $uses = array('Order');
public function buyProduct(){
$data = array(
'user_id' => $this->Auth->user('id'),
'product_id' => 11,
'trans_id' => 12,
'auth_code' => 13
);
$this->Order->create();
$this->Order->save($data);
}
Upvotes: 1
Reputation: 1268
I assumed that you are using CakePHP 2.x. Try something like this:
public function buyProduct(){
$data['Order'] = array(
'user_id' => $this->Auth->user('id'),
'product_id' => 11,
'trans_id' => 12,
'auth_code' => 13
);
$this->loadModel('Order');
$this->Order->create();
$this->Order->save($data);
}
Upvotes: 0