Handling Multiple URL Values ​​in CakePHP

I am developing a site using the CakePHP framework. I have a form that shows a list of entities, with a ticket for each one allowing you to select it. Then click the button at the bottom of the form, indicating "Edit Selected."

My usual approach is to have each checkbox enter the same name (for example row_id

) and use the primary id as input value

. However, when you submit the form, CakePHP seems to return one of the checkbox values ​​to the controller in $this->params['url']

, rather than any list as I expected.

Any hints on the correct way to handle this so I can find out which lines were checked?

0


a source to share


1 answer


If you are using FormHelper the easiest way is to create your fields like this:

echo $form->input('ModelName.0.row_id', /* snip */)
echo $form->input('ModelName.1.row_id', /* snip */)

      

Etc. you understand. If it is a dynamic list, there is always a loop for

.



When the form is POSTED, this should give you a server-side array ($ this-> data) like this:

array
(
    ['ModelName'] => array
    (
        [0] => array
        (
            [row_id] => value
        ),
        [1] => array
        (
            [row_id] => value
        )
    )
)

      

Then you can use the Set utility class to retrieve your ids (and mess with your data :))

+1


a source







All Articles