Saving Multiple Select in input

前端 未结 3 1422
攒了一身酷
攒了一身酷 2021-01-28 16:38

I have model for

  • user(id,name)
  • section(id,name)
  • section_users(id,user_id,section_id)

The admin adds all the users and sections

3条回答
  •  别那么骄傲
    2021-01-28 17:25

    This is HABTM relation, first of all you need have relation setup in SectionUser model. Then you can use saveAll() method to save all records at once.

    Array
    (
        [0] => Array
        (
            [user_id] => 33
            [section_id] => 9
        )
    
        [1] => Array
        (
            [user_id] => 33
            [section_id] => 10
        )
    )
    

    Make sure your data array is in above given format.

    $this->SectionUser->saveAll($data);
    

提交回复
热议问题