0

我正在尝试将数组保存为如下所示的数组,其中 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));

4

1 回答 1

1

该数据结构可以与 saveAll 一起使用,您尝试过吗?

<?php

$this->Model1->saveAll($myarray, array('deep' => true));

?>

saveAll 在内部调用 saveAssociated。

我相信这对你有用。

于 2013-04-11T20:02:46.010 回答