0
In a user form, I upload information such as username, password and permissions.
But now I’ve included it in the permissoes
a field called grupo
.
And I included it in the usuarios
this field, so that; every time the user’s permission is chosen, the group field loads the group name of the selected permission group.
I know that in MYSQL, the querie used is
`SELECT `grupo` FROM `permissoes` WHERE `id` = 1`.
But I couldn’t do it in the codeigniter.
In the edit function,
I retrieve user data and display the information in the view as follows:
User Controller
//Obtem dados do usuário
$this->data['usuarios'] = $this->Usuarios_model->obter_id($this->uri->segment(4));
//Obtem Permissões Ativas
$this->data['permissoes'] = $this->Permissoes_model->obter_ativo('permissoes', 'permissoes.id,permissoes.nome');
//Carrega View
$this->template->admin_render('admin/usuarios/editar', $this->data);
Model User:
//Função obter ID
function obter_id($id){
$this->db->select('usuarios.*, permissoes.nome as permissao');
$this->db->select('usuarios.*, permissoes.grupo as grupo');
$this->db->join('permissoes', 'usuarios.permissoes_id = permissoes.id', 'left');
$this->db->where('usuarios.id',$id);
$this->db->limit(1);
return $this->db->get('usuarios')->row();
}
Model Permissions
//Exibir somente permissões ativas
function obter_ativo($tabela,$campos){
$this->db->select($campos);
$this->db->from($tabela);
$this->db->where('situacao',1);
$query = $this->db->get();
return $query->result();;
}
View User
//View do formulário usuário
<select name="permissoes_id" id="permissoes_id" class="form-control">
<?php foreach ($permissoes as $permissao) {
if($permissao->id == $usuarios->permissoes_id){ $selected = 'selected';}else{$selected = '';}
echo '<option value="'.$permissao->id.'"'.$selected.'>'.$permissao->nome.'</option>';
} ?>
</select>
<label>Grupo</label>
<input "Aqui vai o nome do grupo referente a permissão selecionada" />
User tables
`id` INT(11) NOT NULL AUTO_INCREMENT,
`primeiro_nome` VARCHAR(40) NOT NULL,
`ultimo_nome` VARCHAR(40) NOT NULL,
`nome_usuario` VARCHAR(40) NOT NULL,
`telefone` VARCHAR(20) NULL DEFAULT NULL,
`email` VARCHAR(80) NOT NULL,
`senha` VARCHAR(45) NOT NULL,
`permissoes_id` INT NOT NULL,
`grupo` INT NOT NULL,
Tables Permissions
`id` INT(11) NOT NULL AUTO_INCREMENT,
`nome` VARCHAR(80) NOT NULL,
`descricao` VARCHAR(80) NULL DEFAULT NULL,
`grupo` INT NOT NULL,
`permissoes` TEXT NULL,
`situacao` TINYINT(1) NULL,
Where is the error or problem?
– user26552
No error, what I want is to recover the group related to permission.
– Wagner Fillio
See in the image above, you will have an idea. For each permission there is a group. Example: Admin Permission - group 1, Permission Support - group 2, Permission Operation - group 1; I want to recover the group according to the selected permission.
– Wagner Fillio
Who is retrieving permissions groups?
obter_ativo()
?– ShutUpMagda
Yes, get it active()
– Wagner Fillio
Makes
print_r($query->result())
on the way out ofobter_ativo()
and shows here, Please.– ShutUpMagda
But printing this way
print_r($query->result())
on the model, will show me the result where?– Wagner Fillio
But using
print_r($this->data['permissoes']);
, haveArray
(
 [0] => stdClass Object
 (
 [id] => 1
 [nome] => Administrador
 )

)
– Wagner Fillio
It’s the same thing, but from what I can tell, the group isn’t there... this object only has id and name...
– ShutUpMagda
That’s the only reason I got it.
Array ( [0] => stdClass Object ( [id] => 1 [nome] => Administrador [grupo] => 1 ) )
– Wagner Fillio
Can you leave dynamic? Type, when changing select, also change the permission related group?
– Wagner Fillio
Thus: http://answall.com/a/185636/42307
– ShutUpMagda
Possible duplicate of Select(combobox) Dynamic
– ShutUpMagda
But this Naum would be in the same table. Example:
id = 1, permissão = admin, grupo = 1
– Wagner Fillio
It doesn’t matter. The logic is the same. You just need to do in your model one method to recover permissions and another to retrieve groups.
– ShutUpMagda