How to access a variable array codeigniter

3

I have difficulty getting values inside an array variable in codeigniter Help me understand how this works once and for all I made a search in the database that is sent to the view by an array: Controller

$dados= array(
'perfil' => $this->perfil->perfil($id)
);

In the view I have the data that came from the controller. I check my $ profile variable with var_dump($perfil) and this appears:

Array
(
[0] => stdClass Object
(
[artigo_id] => 2
[artigo_titulo] => A volta de cristo
[artigo_imagem] => 8f5364fb6f5204224529ce3345073906.jpg
[artigo_autor] => Nativo Natan Melo
)
)

How do I get index information article_autor? I try to access

$perfil->artigo_autor;

More of an error:

  

Trying to get property of non-object.

How should I proceed?

    
asked by anonymous 14.10.2016 / 20:18

1 answer

2
If the $this->perfil->perfil($id) method should return only a single record, change its return from result() or result_array() to row() so zero index is not created and direct access to object properties.

Example change:

$query = $this->db->query("YOUR QUERY");
return $query->result();

To:

$query = $this->db->query("YOUR QUERY");
return $query->row();

Recommended reading:

Documentation - row ()

    
14.10.2016 / 20:34