Welcome Guest, Not a member yet? Register   Sign In
Table Error
#1

[eluser]mrwilson1[/eluser]
I am getting this error when I load a page from the controller.

Quote:A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: libraries/Table.php

Line Number: 269

My controller code is
Code:
function index() {
        $this->load->model('work_m');
        $data = array();
        if ($query = $this->work_m->get_records()) {
            $data['result'] = $query;
        }
                    
        $config['per_page'] = $this->uri->segment(3);
        $config['base_url'] = base_url().'index.php/work/index/';
        $config['total_rows'] = '200';
        $config['per_page'] = '20';
        $config['uri_segment'] = '3';
        $config['full_tag_open'] = '<p>';
           $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
                
        $this->table->set_heading('ID', 'Date', 'Title', 'Item', '% Comp', 'Finished');
        $data['title'] = 'Page Display';
        $data['content'] = 'todo/work_display';
        $this->load->view('template3', $data);

My view code is

Code:
echo $this->table->generate($result);
echo $this->pagination->create_links();

My model is simply
Code:
function get_records()
    {
        $query = $this->db->get('work');
        return $query->result();
    }


The pagination works fine, but I do not understand what to do about this error. My data in the db is simple, 2 dates, a numeric field, and two text fields. Very simple stuff.

Thank you in advance
#2

[eluser]mrwilson1[/eluser]
In my model I replaced

Code:
return $query->result();


with


Code:
return $query;


that seemed to do the trick, not at all sure why Smile
#3

[eluser]BrianDHall[/eluser]
It has to do with how you are accessing $query in your view $result() returns an Array of Objects, so in the first instance if you didn't refer to it with something like $query[0]->id then it would throw weird errors.

Returning $query directly just returns a bit more simple of an object. Here's the full reference on the various return functions - have to read carefully because some are very similar, yet significantly different from each other. http://ellislab.com/codeigniter/user-gui...sults.html
#4

[eluser]mrwilson1[/eluser]
Thanks Brian, will read further right now. Appreciate you




Theme © iAndrew 2016 - Forum software by © MyBB