在离子验证创建用户使用form_dropdown时将用户添加到组(Add user to group

2019-09-18 05:57发布

我加入权威性的功能create_user控制器():

if ($this->ion_auth->is_admin())
        {    
            $this->data['groups'] = $this->ion_auth->groups()->result_array(); // выбираем все группы
            $groups=$this->data['groups'];
        } 
...
if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data, $groups)) 
...

其次,鉴于我添加下拉字段,并希望从表“群体”的所有组来填充它:

<div class="grid_8"><p>Добавить в группы:<br />

    <?php echo form_dropdown('groups',$groups) ?></p></div> 

但我得到mistaked下拉列表:

0
    1
    admin
    Administrator
1
    2
    moderator
    Moderator
...

请帮助我了解如何使所有群体的好名单:

Administrator
Moderator
User
...

Answer 1:

我在ion_auth_model.php这样做

/**
 * group list
 *
 * @return array
 * @author Susilo N
 **/
public function grouplist()
{
    $query = $this->db->get('groups');

    foreach ($query->result() as $row)
            {
                  $listArray[$row->id] = $row->name;                
            }               

    return $listArray;
}

然后我在控制器添加此

$this->data["listGroups"] = $this->ion_auth->grouplist();

并在视图

<?= form_dropdown('groups', $listGroups, '1') ?>


文章来源: Add user to groups when creating user in Ion Auth using form_dropdown