问题
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