Welcome Guest, Not a member yet? Register   Sign In
Help accessing an array returned from a method within the view
#1

[eluser]Unknown[/eluser]
Hi

I am new to OO style programming and am extending a class in CI.

Can anyone tell the best way to access an array returned by a method within the view? I would have thought something like print $this->method_name()['index'] would have worked? But it doesn't seem too.

I could always set the results to a variable and access them that way, however I am trying to keep the code in the view simple and this complicates things.

Thoughts would be appreciated.

Thanks in advance :-)
#2

[eluser]cahva[/eluser]
[quote author="millenniumdarren" date="1285558231"]
I could always set the results to a variable and access them that way, however I am trying to keep the code in the view simple and this complicates things.
[/quote]

Thats the key to keep things simple in a view. Put results in a variable from controller and pass it to the view. For example:

Controller
Code:
function show_user($id=FALSE)
{
    if (!$id)
    {
        return FALSE;
    }
    
    $this->load->model('users_model');
    
    $data['user'] = $this->users_model->get_user($id);
    
    $this->load->view('show_user',$data);
}

Now when you pass that $data to your view, you will have $user variable to work with in there

View
Code:
<h1>Information for user &lt;?php echo $user->name ?&gt;</h1>
...




Theme © iAndrew 2016 - Forum software by © MyBB