Home > Cakephp > Lưu ý về class model với framework cakephp

Lưu ý về class model với framework cakephp

 

tại class model ./app/Model/product.php khai báo như  sau:

class Product extends AppModel
{

private static $_db;

public function __construct() {
$this->_db = $this->getDataSource();
}

}

Nếu bạn khai báo __construct tại class model, lúc này bạn không thể gọi phương thức save, saveAll ,…tại class controller

./app/Controller/Product.php

 

$this->loadModel(‘product’);
$data[‘product’][‘name’] = $request[‘name’];
$data[‘product’][‘qty’] = $request[‘qty’];
$this->product->save($data);
$insertID = $this->product->getLastInsertID();

 

phương thức $this->product->save($data); sẽ không chạy & báo lỗi

 

PHP Developer
nhantam

 

Advertisements
Categories: Cakephp
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: