ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Fatal error: Call to undefined method CI_Loader::result()

January 09, 2010 10:21pm

Subscribe [4]
  • #1 / Jan 09, 2010 10:21pm

    face1m

    12 posts

    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 ): ?>

    <?=$row->title?>

      <?=$row->body?>
      <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>

  • #2 / Jan 09, 2010 11:44pm

    WebsiteDuck

    93 posts

    In your controller, change:

    function index()
      {
      
      $data['title'] = 'My Blog Title';
      $data['heading'] = 'My Blog Heading one';
      $query = $this->db->get('enteries'); //Possible typo here? enteries
      $data['results'] = $query->result_array();
      
      $this->load->view('blog_viewer', $data);
      }

    In your view change:

    <?php foreach ( $results as $row ): ?>
  • #3 / Jan 10, 2010 8:02am

    Jamie Rumbelow

    546 posts

    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:

    <?php foreach($query->result() as $row): ?>

    When in doubt, read the user manual - it’s very comprehensive. Hope this has helped.

    Jamie

  • #4 / Jan 10, 2010 10:52am

    face1m

    12 posts

    Jamie websiteduck:

    Thanks its working now. Many thanks
    rick

  • #5 / Nov 22, 2011 12:27am

    Suresh Kumar

    2 posts

    Call to undefined method CI_Loader::scaffolding() when i run

    {
    parent::__construct();
    $this->load->scaffolding('comment');
    }
    on controller
    please help me

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases