php - Save multiple inputs with same name to different rows in cakePHP -
i have group of inputs each same name, shown in picture
i want save each category each number of rooms , standard rate. category inputs have same name (<input name="category[]">) same no. of rooms , standard rate.
so far i've tried:
foreach($data['category'] $cat){ $this->model->save($cat) //will save categories without no. of rooms , standard rate. } is there way can foreach through 3 groups of inputs , save data in different rows accordingly? table columns named after inputs name.
this simple achieve using formhelper , savemany. firstly in view want include form elements using formhelper using like:-
echo $this->form->input('model..category'); where need replace model model alias. .. cause output input name model[][category]. if want control numeric index (for example in loop associate other fields) can change $this->form->input('model.1.category') produce input name model[1][category].
then in controller can save data using savemany:-
$this->model->savemany($this->request->data); again replacing model model's alias.
Comments
Post a Comment