我正在尝试根据选择和输入动态生成学期行,并将所有行存储在同一位置。
<pre>
public function saveData() {
$this->autoRender = false; // Disable view rendering
if ($this->request->is('post')) {
$data = $this->request->data;
// Assuming you have a model called Data in your application
$this->loadModel('ETest');
foreach ($data as $row) {
$this->ETest->create();
$entity = array(
'cycle' => $row['cycle'],
'course' => $row['course'],
'year' => $row['year'],
'semester' => $row['semester']
);
$this->ETest->save($entity);
}
$response = array('message' => 'Data saved successfully.');
echo json_encode($response);
}
</pre>```
This is my controller method.
你可以使用
$this->ETest->saveMany($this->request->data)
或者你可以添加
$this->ETest->clear();
调用 ->save() 之后我建议添加
'fieldList' => ['cycle', 'course', 'year', 'semester']
出于安全原因