CakePHP HABTM表单问题

时间:2013-02-03 14:13:22

标签: forms cakephp has-and-belongs-to-many

我有一个关于如何一次保存多个HABTM关系的简单问题。 我知道我的数组必须是我即将发布的所有条目的索引数组,就像那样

array(
 [0] => array(
   Model1 => array
      field => value
   Model2 => array
      field => value
 [1] => array(
   Model1 => array
      field => value
   Model2 => array
      field => value

但是当我使用以下输入表单(通过循环生成并传递给$ this-> Form->输入帮助程序)时

$array[$count . '.Menu.week'] = array('type' => 'hidden', 'value' => $week);
$array[$count . '.Menu.day'] = array('type' => 'hidden', 'value' => 1);
$array[$count . '.Dish.id'] = array('type' => 'select', 'label' => false, 'options' => $dishes);

我得到的是:

array(
    (int) 0 => array(
        'Menu' => array(
            'week' => '06',
            'day' => '1'
        )
    ),
    'Menu' => array(
        (int) 0 => array(
            'Dish' => array(
                'id' => '1'
            )
        ),
        (int) 1 => array(
            'Dish' => array(
                'id' => '1'
            )
        )
    ),
    (int) 1 => array(
        'Menu' => array(
            'week' => '06',
            'day' => '2'
        )
    )
)

如何从结果数组中的Menu键中获取“Dish”值?谢谢!

0 个答案:

没有答案