3
Seeing that I have the following method:
Controller
public function get_objeto($permissao_id)
{
if ($permissao_id == 0)
{
$permissao_id = $permissao_id;
$dados = $this->permissao->get($permissao_id);
echo json_encode($dados, JSON_NUMERIC_CHECK);
}
else
{
$dados = $this->permissao->get_by_id($permissao_id);
echo json_encode($dados, JSON_NUMERIC_CHECK);
}
}
Model
// get_by_id
public function get_by_id($permissao_id)
{
$result = array();
$result = $this->get_data($permissao_id);
return $result;
}
// get_data
public function get_data($permissao_id)
{
$this->db->select('id, nome, permissoes tree_funcao, grupo_id');
$this->db->from($this->tabela);
$this->db->where('id',$permissao_id);
$query = $this->db->get();
$item = $query->row();
return $item;
}
And the following return from the database:
{"id":3,"nome":"teste","tree_funcao":"a:7:{i:0;a:9:{s:2:\"id\";s:1:\"1\";s:4:\"text\";s:9:\"Dashboard\";s:4:\"icon\";s:23:\"fa fa-folder text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"1\";}s:6:\"a_attr\";O:8:\"stdClass\":2:{s:4:\"href\";s:1:\"#\";s:2:\"id\";s:8:\"1_anchor\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"#\";s:4:\"type\";s:5:\"grupo\";}i:1;a:9:{s:2:\"id\";s:1:\"2\";s:4:\"text\";s:14:\"Configura\u00e7\u00e3o\";s:4:\"icon\";s:23:\"fa fa-folder text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"2\";}s:6:\"a_attr\";O:8:\"stdClass\":2:{s:4:\"href\";s:1:\"#\";s:2:\"id\";s:8:\"2_anchor\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"#\";s:4:\"type\";s:5:\"grupo\";}i:2;a:9:{s:2:\"id\";s:1:\"3\";s:4:\"text\";s:8:\"Usu\u00e1rio\";s:4:\"icon\";s:34:\"fa fa-angle-double-right text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"3\";}s:6:\"a_attr\";O:8:\"stdClass\":2:{s:4:\"href\";s:1:\"#\";s:2:\"id\";s:8:\"3_anchor\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"2\";s:4:\"type\";s:6:\"funcao\";}i:3;a:9:{s:2:\"id\";s:1:\"4\";s:4:\"text\";s:5:\"Criar\";s:4:\"icon\";s:20:\"fa fa-lock text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"4\";}s:6:\"a_attr\";O:8:\"stdClass\":1:{s:4:\"href\";s:1:\"#\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"3\";s:4:\"type\";s:4:\"acao\";}i:4;a:9:{s:2:\"id\";s:1:\"5\";s:4:\"text\";s:6:\"Editar\";s:4:\"icon\";s:20:\"fa fa-lock text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"5\";}s:6:\"a_attr\";O:8:\"stdClass\":1:{s:4:\"href\";s:1:\"#\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"3\";s:4:\"type\";s:4:\"acao\";}i:5;a:9:{s:2:\"id\";s:1:\"6\";s:4:\"text\";s:7:\"Excluir\";s:4:\"icon\";s:20:\"fa fa-lock text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"6\";}s:6:\"a_attr\";O:8:\"stdClass\":1:{s:4:\"href\";s:1:\"#\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"3\";s:4:\"type\";s:4:\"acao\";}i:6;a:9:{s:2:\"id\";s:1:\"8\";s:4:\"text\";s:10:\"Visualizar\";s:4:\"icon\";s:20:\"fa fa-lock text-osun\";s:7:\"li_attr\";O:8:\"stdClass\":1:{s:2:\"id\";s:1:\"8\";}s:6:\"a_attr\";O:8:\"stdClass\":1:{s:4:\"href\";s:1:\"#\";}s:5:\"state\";O:8:\"stdClass\":4:{s:6:\"loaded\";b:1;s:6:\"opened\";b:0;s:8:\"selected\";b:1;s:8:\"disabled\";b:0;}s:4:\"data\";O:8:\"stdClass\":0:{}s:6:\"parent\";s:1:\"3\";s:4:\"type\";s:4:\"acao\";}}","grupo_id":1}
How can I
unserializar
only the columntree_funcao
, keeping the other fields as they are ?
so I’ve done and seen that it works. It turns out that this associative array is in a table field, but the other fields are not array. So how can I return the other fields too?
– Wagner Fillio
So just make $data_array['id'] so on @Wagnerfilho ... Got it.!?
– novic
@Wagnerfilho edited response!
– novic
I put an answer based on your answer, so I have given your answer. I have only one question, if you can help me. As you can see, inside the key
tree_funcao
in each index of the array, there is an item, calledstate
. It is possible to go through all indexes and get the valueselected
ofstate
of each travel index?[state] => stdClass Object
 (
 [loaded] => 1
 [opened] => 
 [selected] => 1
 [disabled] => 
 )
– Wagner Fillio
@Wagnerson has yes just do a for and then access
state->selected
...– novic
something like
foreach ($item['tree_funcao'] as $tree_funcao => $item)
 {
 echo ($tree_funcao);
 //echo ($tree_funcao['state']['selected']);
 }
– Wagner Fillio
$tree_funcao['state']->selected
@Wagnerfilho– novic
Good morning, can you help me with this question ? https://answall.com/questions/291566
– Wagner Fillio