How to group values in an array in cakephp?

前端 未结 2 1839
一整个雨季
一整个雨季 2021-01-27 17:25

I have a list of teamleads in an array and their corresponding team members in another array.
I need to group them in an array such that under each teamleads the correspondi

相关标签:
2条回答
  • 2021-01-27 18:08

    Follow the conventions of CakePHP and you won't have this problem.

    If you query TeamLead->find() and TeamLead hasAndBelongsToMany or hasMany TeamMember the returned array structure will contain everything you need and in a fashion you can use with the FormHelper methods in the views.

    0 讨论(0)
  • 2021-01-27 18:26

    Get your arrays as a list:

    $this->set('teams', $this->TeamMembers->find('list'));
    

    Then in the form you can set the options:

    $this->Form->input('team_member', array('options' => $teams));
    

    UPDATE You will require javascript / css to manipulate the select field in order to do what you are asking. None of the tags you currently have set will get an answer you are looking for. This cannot be done with regular HTML / PHP code.

    0 讨论(0)
提交回复
热议问题