如果要保存新数据,只需使用Model :: save():
$data = array(
'ModelName' => array(
'foo' => $foo
)
)
// prepare the model for adding a new entry
$this->ModelName->create();
// save the data
$this->ModelName->save($data);
如果要更新数据,只需使用相同的方法,而无需调用Model :: create()
$data = array(
'ModelName' => array(
'id' => $id
'foo' => $foo
)
)
$this->ModelName->save($data);
编辑:
我猜这就是你要找的东西:
$this->ModelName->id = $id;
if (!$this->ModelName->exists()) {
$this->ModelName->create();
}
$this->ModelName->save($data);