Fatal error: Call to undefined method CI_Loader::result() - 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: Fatal error: Call to undefined method CI_Loader::result() (/showthread.php?tid=26259) |
Fatal error: Call to undefined method CI_Loader::result() - El Forum - 01-09-2010 [eluser]face1m[/eluser] I am following the second video tutorial on creating a blog. All of the code has worked up to this point. But i can not find the cause of this error. See code below. thanks in advance for your help. I'm using php 5 rick <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?=$title?></title> </head> <body> <h1><?=$heading?></h1> <?php foreach ( $this->result() as $row ): ?> <h3><?=$row->title?></h3> <p><?=$row->body?></p> <hr /> <?php endforeach; ?> ------------------------------------------------------------------------ <?php class Blog extends Controller { function __construct() { parent::Controller(); } function index() { $data['title'] = 'My Blog Title'; $data['heading'] = 'My Blog Heading one'; $data['query'] = $this->db->get('enteries'); $this->load->view('blog_viewer', $data); } } ?> </body> </html> Fatal error: Call to undefined method CI_Loader::result() - El Forum - 01-09-2010 [eluser]WebsiteDuck[/eluser] In your controller, change: Code: function index() In your view change: Code: <?php foreach ( $results as $row ): ?> Fatal error: Call to undefined method CI_Loader::result() - El Forum - 01-10-2010 [eluser]Jamie Rumbelow[/eluser] Hello Rick, Firstly, welcome to the CodeIgniter community! You're trying to call result() on the CI master object - which is definitely not a good idea. result() is a method given to you by the DB result object, which is returned by $this->db->get() or $this->db->query(). In your controller, you assigned the result object to $data['query'], so in the view it's available as $query. Knowing this, we just have to change the foreach loop in your view and it all should work: Code: <?php foreach($query->result() as $row): ?> When in doubt, read the user manual - it's very comprehensive. Hope this has helped. Jamie Fatal error: Call to undefined method CI_Loader::result() - El Forum - 01-10-2010 [eluser]face1m[/eluser] Jamie websiteduck: Thanks its working now. Many thanks rick |