表單(newreports.php)在提交時需要保存到表中,並將隱藏數據(每條記錄有7列的27條記錄)保存到BelongsTo表中。 7列是:id,user_id,reports_id,count,area,area_id,comments。區域需要預填充爲0-26,並且reports_id對於所有(100)需要相同。 User_id應該從表單條目中預先填寫。另外,id應該自動填充。我認爲這可以在我的控制器中爲函數newreports()完成。如何在cakePHP中保存多個表屬於?
我需要寫這樣的數組還是有簡化的方法?
$this->Report->saveAll(
Array
(
[Report] => Array
(
[0] => Array
(
[id] => //leave blank because it will auto-fill?
[user_id] => //dynamically from form input
[reports_id] => //dynamically from form input
[area_id] => //dynamically from form input
[area] => 0
[count] => // this should be blank as there are no counts yet
[comments] => // this should be blank as there are no comments yet
)
[1] => Array
(
[id] => //leave blank because it will auto-fill?
[user_id] => //dynamically from form input
[reports_id] => //dynamically from form input
[area_id] => //dynamically from form input
[area] => 1
[count] => // this should be blank as there are no counts yet
[comments] => // this should be blank as there are no comments yet
)
)
)
這個數組是不是從一個表單輸入也沒有爲它的視圖。它是隱藏的。我不希望人們看到它。我需要它在後臺運行,自動填充或預先填充數據庫表,然後將用戶重定向到可以編輯此數據的視圖。它包含一些需要保存或插入到數據庫的靜態和一些動態分配的值。目前,這是在我的控制器中。這個數組將如何分配給$ data? – sloga