Question

I have this situation. From the BiograpiesController, after a query, I get this array:

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

In the View I want create a Form whit this data. I use:

    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( );

The first field is filled with the correct data, the second is empty. Then I try:

    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'] ));

The field A1 is filled with the correct data and the second is empty. Why is this happening? How can I fill the form with the correct data that I have in the controller?

Thank you very much

Était-ce utile?

La solution

I don''t have much knowledge of cakephp but as per the document it should work

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( );

Please note the change at 2 and 3rd line

I have referred following link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#field-naming-conventions

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top