dtzjvj3915 2014-10-19 20:02
浏览 14

保存多个选择输入

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 separately. Once theses are added I want the admin to selects the section and add all the users in it in section_users


I have a select input with multiple set to true. How do i save this data the cakephp way along with validation.

<?php echo $this->Form->input("section_id"); ?>
<?php echo $this->Form->input("user_id", array('multiple'=>'checkbox')); ?>

This generates

Array
(
    [section_id] => 1
    [user_id] => Array
        (
            [0] => 3
            [1] => 4
        )

)

I know i can loop and convert to this and use saveAll or saveMany but what is the cakephp way/right way to do it.

Array
(
    [0] => Array
        (
            [section_id] => 1
            [user_id] => 3
        )
    [1] => Array
        (
            [section_id] => 1
            [user_id] => 4
        )

)
  • 写回答

3条回答 默认 最新

  • duandi6531 2014-10-19 20:31
    关注

    CakePHP has the saveMany function, as mentioned in the documentation:

    Model::saveMany(array $data = null, array $options = array())¶
    
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。