Add user to groups when creating user in Ion Auth using form_dropdown

偶尔善良 提交于 2020-01-02 10:19:17

问题


I add to auth controller in function 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)) 
...

Next in view I add dropdown field and want to populate it with all groups from table 'groups':

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

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

but I get mistaked dropdown list:

0
    1
    admin
    Administrator
1
    2
    moderator
    Moderator
...

Please help me understand how to make good list of all groups:

Administrator
Moderator
User
...

回答1:


I did this in 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;
}

then I add this at controller

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

and in the view

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


来源:https://stackoverflow.com/questions/11098339/add-user-to-groups-when-creating-user-in-ion-auth-using-form-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!