我正在尝试使用saveAssociated和深度选项设置为true来保存数组,如下所示,但它不保存答案,只保存测验和问题。我正在使用CakePhp 2.3.1
$myarray = array(
'Quiz' => array(
'title' => 'Test di Prova copy',
'description' => '',
'timer' => '5',
'days' => '10',
'tries' => '2',
'pass_percentage' => '90',
'active' => true
),
'Question' => array(
(int) 0 => array(
'question' => 'Quanti valori può assumere un bit?',
'score' => '10',
'position' => '0',
'created' => '0000-00-00 00:00:00',
'modified' => '2013-04-10 13:04:50',
'Answer' => array(
(int) 0 => array(
'answer' => '2',
'right' => true
),
(int) 1 => array(
'answer' => '4',
'right' => false
),
(int) 2 => array(
'answer' => '8',
'right' => false
),
(int) 3 => array(
'answer' => 'non lo sò
',
'right' => false
)
)
),
(int) 1 => array(
'question' => 'Quale tra questi tag Html identifica l'header più grande di dimensioni?',
'score' => '10',
'position' => '2',
'created' => '0000-00-00 00:00:00',
'modified' => '2013-04-10 13:04:50',
'Answer' => array(
(int) 0 => array(
'answer' => 'H6',
'right' => false
),
(int) 1 => array(
'answer' => 'H4',
'right' => false
),
(int) 2 => array(
'answer' => 'H1',
'right' => true
)
)
),
(int) 2 => array(
'question' => 'Da quanti bit è composto un byte?',
'score' => '10',
'position' => '1',
'created' => '0000-00-00 00:00:00',
'modified' => '2013-04-10 13:04:50',
'Answer' => array(
(int) 0 => array(
'answer' => '2',
'right' => false
),
(int) 1 => array(
'answer' => '4',
'right' => false
),
(int) 2 => array(
'answer' => '6',
'right' => false
),
(int) 3 => array(
'answer' => '8',
'right' => true
)
)
)
)
);
$ this-> Quiz-> saveAssociated($ myarray,array('deep'=> true));
答案 0 :(得分:1)
该数据结构适用于saveAll,你试过吗?
<?php
$this->Model1->saveAll($myarray, array('deep' => true));
?>
saveAll在内部调用saveAssociated。
我相信这应该适合你。