Welcome Guest, Not a member yet? Register   Sign In
Using Objects in Views
#1

[eluser]ChrisMcABZ[/eluser]
Hi there. Forgive me if this has been covered already; I tried searching, but couldn't find what I was looking for.

I'm starting to roll my first CI application using 1.6.0 - it's a simple CMS for my personal site. What I would like to do is this (code shortened for berevity):

(model)
Code:
public function GetBySlug($slug='')
{
    $entry['slug'] = $slug;
        
    return $this->db->get_where('entries', $entry)->result();
}

(controller)
Code:
$data['entry'] = $this->Entry->GetBySlug($slug);
$this->load->view('entry', $data['entry']);
(view)
Code:
<h1>&lt;?= $entry->title; ?&gt;</h1>

But with this code I just get an error. If I write this instead -

Code:
<h1>&lt;?= $entry[0]->title; ?&gt;</h1>

or use a loop, it works, but that seems a waste for what will always be a single result - and it's not as pretty Smile . Am I missing something (probably something very basic!)? Or do I have to give up my objects in views and start passing result_array() instead?

Thanks in advance, CI Bods!


Messages In This Thread
Using Objects in Views - by El Forum - 02-07-2008, 04:36 PM
Using Objects in Views - by El Forum - 02-07-2008, 05:28 PM
Using Objects in Views - by El Forum - 02-07-2008, 10:48 PM
Using Objects in Views - by El Forum - 02-08-2008, 12:31 AM
Using Objects in Views - by El Forum - 02-08-2008, 12:57 AM
Using Objects in Views - by El Forum - 02-08-2008, 11:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB