开发者

CakePHP Model index array needed, but can't generate from for loop counter. Need model indexed array for this to work

I am working on a function that submits multiple records on various relationship types. The main issue I am running into is the format of the array. In order for my saveAll() to work on my multiple relationships setup, the array needs to be in this format as you can see the models are Keys (first array below).

My main question is: 1) Is it possible to strip the numerical indexes off the second layer of the second array below?

I am returning my input fields like so. You can see the prefixed counter (which I believe is what is creating the numeric index on that second level).

<?php echo $this->Form->input("$i.monthly_cost", array('label' => 'Monthly Cost')); ?>

I am using a for loop counter for the fields. So my question number to is: can this for value be changed to something that will work with Cake's saveAll()?

<?php for ($i = 1; $i <= 2; $i++) { ?>

Example where models are the keys (this is the format I need):

Array
(
[User] => Array
    (
        [username] => billy
    )
[Profile] => Array
    (
        [sex] => Male
    [occupation] => Programmer
    )

The only output I can get on my multiple input array (below is the debug() dump)

My actual output is numerically indexed:

Array
(
[Plan] => Array
    (
        [1] => Array
            (
                [plan_detail_id] => 36
                [monthly_cost] => 0
                [dental_cost] => 0
                [age_id] => 14
                [applicant_id] => 1
                [state_id] => 1
            )

        [2] => Array
            (
                [plan_detail_id] => 36
                [monthly_cost] => 0
                [dental_cost] => 0
                [age_id] => 2
                [applicant_id] => 4
                [state_id] => 1
            )

    )

[1] => Array
    (
        [1] => Array
            (
                [Zip] => Array
                    (
                        [0] => 487
                        [1] => 486
                        [2] => 485
                        [3] => 484
                        [4] => 483
                    )

            )

    )

[2] => Array
    (
        [2] => Array
            (
                [Zip] => Array
                    (
                        [0] => 485
                        [1] => 484
           开发者_运维百科             [2] => 483
                    )

            )

    )

)


Did you already check out the Set Core Utility Library? This can help you out a lot with array management.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜