在cakephp中保存多个索引数组值

时间:2014-04-25 08:24:28

标签: cakephp cakephp-2.0

我想用多个索引数组值保存我的数组。 演示代码

Array
(
    [CodeConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 
                )
        )
    [ObjectAccountConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 2
                )
        )
    [TaxConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 2
                    [IsDirty] => 1
                )

            [1] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 1
                )
        )
)

我想将这些数组值直接保存到表中。表名是audit_trail_details。 所以请建议如何将这些数据保存到表格中。

1 个答案:

答案 0 :(得分:0)

您需要使用saveAssociated并将数组解析为第一个参数: -

$this->AuditTrailDetail->saveAssociated($data);

您还需要确保$ data包含您要保存关联数据的AuditTrailDetail。例如: -

Array
(
    [AuditTrailDetail] => Array
        (
            [id] => 1
        )
    [CodeConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 
                )
        )
    [ObjectAccountConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 2
                )
        )
    [TaxConfiguration] => Array
        (
            [0] => Array
                (
                    [LineNo] => 2
                    [IsDirty] => 1
                )

            [1] => Array
                (
                    [LineNo] => 1
                    [IsDirty] => 1
                )
        )
)