Having problems with the table helper - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Having problems with the table helper (/showthread.php?tid=4919) |
Having problems with the table helper - El Forum - 12-23-2007 [eluser]sundancekid[/eluser] Hi, I'm new to CI and just playing around with it trying to figure it out. Anyhow, I tried an example given in the user guide for generating a table from a database query, but it doesn't work for me. I am trying this: Code: $this->load->library('table'); But I get this error: Code: A PHP Error was encountered I know the db settings are correct I can loop through the query and display the results. The table I'm querying has about 5 fields and 3 rows. Thanks for any help and I lookforward to learning more about CI and getting to know the community here. Having problems with the table helper - El Forum - 12-23-2007 [eluser]imzyos[/eluser] have you load the db class ? Having problems with the table helper - El Forum - 12-23-2007 [eluser]sundancekid[/eluser] I think so. Model: Code: class Examplemodel extends Model { Controler: Code: function examplesearch() Having problems with the table helper - El Forum - 12-23-2007 [eluser]Derek Allard[/eluser] I believe he means, do you have Code: $this->load->database(); Having problems with the table helper - El Forum - 12-23-2007 [eluser]Chris Newton[/eluser] The error you describe is what you'd get if you were using echo $this->table->generate($query->result()); rather than echo $this->table->generate($query); OR what you could get if you forget to load (or autoload) $this->load->database(); Having problems with the table helper - El Forum - 12-23-2007 [eluser]briguy[/eluser] As mahuti said, from your Model, do "return $query;" not "return $query->result()" Having problems with the table helper - El Forum - 12-23-2007 [eluser]sundancekid[/eluser] [quote author="briguy" date="1198475884"]As mahuti said, from your Model, do "return $query;" not "return $query->result()"[/quote] Ok, it works now. Thanks! I am a little confused as to when you need to use $this->load->database(); and when you don't because I didn't and it's working. Having problems with the table helper - El Forum - 12-23-2007 [eluser]Chris Newton[/eluser] I think it may be autoloaded in the config by default. Having problems with the table helper - El Forum - 12-23-2007 [eluser]briguy[/eluser] sundance, Libraries have to be loaded before use, unless they are listed in your ../config/autoload.php in which case they are autoloaded and available throughout your application without need to explicitly load. Look for this line in your autoload.php. $autoload['libraries'] = array('database','session'); I beleive the sandbox download from the ci site has database already in the library autoload array. Brian Having problems with the table helper - El Forum - 12-24-2007 [eluser]imzyos[/eluser] yeah, buy database is not a light library, autoload its a nice feature but give it a little help |