0

我有这种情况。从 BiograpiesController 查询后,我得到了这个数组:

    Array (
            [0] => Array (
                    [Biography] => Array (
                            [id] => 7
                            [biography] => AAA
                    )
            )
            [1] => Array (
                    [Biography] => Array (
                            [id] => 9
                            [biography] => BBBBB
                )
        )
    )

在视图中,我想创建一个包含此数据的表单。我用:

    echo $this->Form->create( 'Biography' ));
    echo $this->Form->input( '0.Biography.biography', array( 'label' => 'A' ));
    echo $this->Form->input( '1.Biography.biography', array( 'label' => 'B' ));
    echo $this->Form->end( );

第一个字段填充了正确的数据,第二个字段为空。然后我尝试:

    echo $this->Form->input( 'A1', array( 'type' => 'textarea', 'rows' => '10', 'cols' => '40', 'value' => $this->request->data[0]['Biography']['biography'] ));
    echo $this->Form->input( 'B1', array( 'type' => 'textarea', 'rows' => '10', 'cols' => '40', 'value' => $this->request->data[1]['Biography']['biography'] ));

字段 A1 填充了正确的数据,第二个字段为空。为什么会这样?如何使用控制器中的正确数据填写表格?

非常感谢

4

1 回答 1

2

我对 cakephp 了解不多,但根据文档,它应该可以工作

echo $this->Form->create( 'Biography' ));
echo $this->Form->input( 'Biography.0.biography', array( 'label' => 'A' ));
echo $this->Form->input( 'Biography.1.biography', array( 'label' => 'B' ));
echo $this->Form->end( );

请注意第 2 行和第 3 行的更改

我参考了以下链接 http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#field-naming-conventions

于 2014-03-03T10:15:24.403 回答