Welcome Guest, Not a member yet? Register   Sign In
Error while creating table with HTML Table Class
#1

[eluser]Sytze Loor[/eluser]
I'm pretty new to CI, but until now I worked wonderful for me.
This morning, however, I've bumped into a little problem.

I have a controller with an index function that's getting some data from the database and calling a view after that.
In the view I try to create a table using the standard HTML Table class. But this gives a PHP error on: "Call to a member function set_heading() on a non-object in"

Here is part of the relevant source code:
Code:
// Controller:
  function index() {
    $users = $this->user->getUserList(); //$this->user is referring to the User model
    $vdMain = array('users' => $users);
    $this->load->view('front/users/list', $vdMain);
  }

// View:
  $this->table->set_heading(' ', 'Screenname', 'Registered at', 'Last login');
  foreach($users as $user):
    $this->table->add_row(' ');
    $this->table->add_row($user['screenname']);
    $this->table->add_row($user['created_datetime']);
    $this->table->add_row($user['login_last']);
  endforeach;
  echo $this->table->generate();

Notes:
* I've added the table library to the autoload in config
* When I try to created a table using HTML it works
* I've placed my application folder in the root of the site (outside the system folder)

* I'm not really sure where to post this question, I'm sorry if I posted it wrong...

Thank you!
Sytze Loor
#2

[eluser]thinkigniter[/eluser]
Code:
// Controller:
  function index() {
    $users = $this->user->getUserList(); //$this->user is referring to the User model
    $vdMain = array('users' => $users);
    $this->load->view('front/users/list', $vdMain);
  }

// View:
  $this->table->set_heading('empty', 'Screenname', 'Registered at', 'Last login');
  foreach($users as $user):
    $this->table->add_row('empty');
    $this->table->add_row($user['screenname']);
    $this->table->add_row($user['created_datetime']);
    $this->table->add_row($user['login_last']);
  endforeach;
  echo $this->table->generate();
[/quote]
Hi Sytze Loor

Things I would check...

1. $users is an array not an object.
2. replace   with 'empty'(for now) ";" maybe causing a problem.

Good Luck!
#3

[eluser]Yash[/eluser]
just add this code into constructor.

Code:
$this->load->helper('html');
#4

[eluser]Sytze Loor[/eluser]
Thank you both for the response, but it didn't solve the problem...
If I remove
Code:
$this->table->set_heading
the script gives the same error on the
Code:
$this->table->add_row
line...

Thank you!
Sytze Loor
#5

[eluser]Yash[/eluser]
Try this

Code:
/ Controller:
  function index() {
/*
    $users = $this->user->getUserList(); //$this->user is referring to the User model
//what is $users  ?? array

//why this line  
  $vdMain = array('users' => $users);*/

//consider $users is array then

$data['users']=$this->user->getUserList();
$this->load->view('front/users/list', $data);

}

// View:
  $this->table->set_heading('empty', 'Screenname', 'Registered at', 'Last login');
  foreach($users as $user):
    $this->table->add_row('empty');
    $this->table->add_row($user['screenname']);
    $this->table->add_row($user['created_datetime']);
    $this->table->add_row($user['login_last']);
  endforeach;
  echo $this->table->generate();

try print_r($users) in view section read array then make table.
#6

[eluser]Sytze Loor[/eluser]
* If it check whether $users is an array (is_array($users)), it returns true.
* I had the line $vdMain in there because it contained more data, not only users. But I've removed it all to do a clean check, but I still get the error...

I've thought some more about the problem and it seems like $this->table is not an object. When I check is_object($this->table) it returns false, that's not correct I suppose.


Sytze
#7

[eluser]Yash[/eluser]
Try without HTML helper.

lemme know results
#8

[eluser]Sytze Loor[/eluser]
I've disabled the HTML helper, but it didn't solve the problem.
If I try to run another library function ($this->uri->array_segments()) for example), it works just fine. Could this be a bug in the Table library. If I try is_object($this->uri) it returns true, as it should (is_object($this->table) returns false for some strange reason).

Sytze
#9

[eluser]Yash[/eluser]
I mean don't do likethis

$this->table->set_heading('empty', 'Screenname', 'Registered at', 'Last login');
foreach($users as $user):
$this->table->add_row('empty');
.
.
endforeach;
echo $this->table->generate();
else
try normal HTML code for table

Now I can't help much without whole structure.
wait for some geek help.
#10

[eluser]Sytze Loor[/eluser]
One of the notes at my initial post was:
* When I try to created a table using HTML it works

So, I guess I'll wait for a geek then Wink




Theme © iAndrew 2016 - Forum software by © MyBB