Welcome Guest, Not a member yet? Register   Sign In
Undefined property in my view. How to output data in the view.

[eluser]Henry Weismann[/eluser]
I have just started with php MVC design pattern frameworks and after researching for a while I have decided to use CodeIgnitor. I have been using php for a few years now and have dabbled in OO techniques in other languages but it is still new to me. I am excited to learn a framework and work on application of OO ideas. Anyway I have what is probably a simple question. I have created a controller a model and a view but my view is giving an error when trying to output the results from my controller. This is the error:
Message: Undefined property: customerName

Filename: views/admin_customers_view.php

Line Number: 12

I am using a foreach for iteration. Here are snippets of my code:

The Model function:

function get_customers($limit,$offset)
        $query = $this->db->get('customerinfo', $limit);
        return $query->result();

The controller function:
function customers($limit = 25, $offset = 0)
        $data['customer'] = $this->Admin_model->get_producers($limit, $offset);
        // Pagination code
        $config['base_url'] = '/admin/producers/'.$limit.'/';
        $config['total_rows'] = $this->db->count_all('movieproducers');
        $config['per_page'] = $limit;
        $config['uri_segment'] = 4;
        $data['pagination'] = $this->pagination->create_links();

In the view:
&lt;?php foreach($customer as $item):?&gt;


&lt;?php endforeach;?&gt;
    <br/><br/>&lt;?=$pagination ?&gt;</center>

Can anyone tell me what I am doing wrong. Is $data['customer'] an array or object. Maybe I am missing my fundamentals on iterating through an object.

[eluser]Henry Weismann[/eluser]
NEVERMIND I see my problem:

I have get_producers mismatced with get_customers. This is waht happens when I copy and paste and then change things. Thanks anyway. That table field does not exist in that table. I guess posting something forces you to look at your code with a better eye.

[eluser]Phil Sturgeon[/eluser]
At least you realised before someone posted back. I always realise my mistake a few mins after posting then as im writing my "dont worry, sorted it" i get spammed by 25 "z0mg yoo n00b!!1" replies.

Theme © iAndrew 2016 - Forum software by © MyBB