Accessing Blog Content Elsewhere


I have an issue with the blog module which I've installed in my Fuel project. The blog module works beautifully on the front-end and the back end.

I'm now trying to put the most recent post on my homepage, however, I keep getting the following error message when calling $this->get_recent_posts(1);
A PHP Error was encountered<br /> Severity: Warning<br /> Message: print_r(): Couldn't fetch mysqli_result<br /> Filename: _layouts/home.php (my view)<br /> Line Number: 58

It repeats this warning about 100 times, then appears to run out of memory like it's stuck in some kind of loop.
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1065357312 bytes) in C:\xampp\htdocs\nordegg\fuel\application\views&#95;layouts\home.php on line 58




  • It's probably calling the __toString() method on a model record which will have recursion since it has a reference to the $CI object within it.

  • Is there a better way to do this then?
    This is all that I'm doing right now:
    <?php $posts = $this->fuel->blog->get_recent_posts(); ?><br /> <?php print_r($posts); $this->db->debug_query(); ?>

    I couldn't find anything in the docs to pull the most recent blog posts from elsewhere on the site, nor any how-to's about doing that.

  • edited December 2020

    Since $posts is an array you can do the following:

    <?php $posts = $this->fuel->blog->get_recent_posts(); ?><br />
    <?php foreach ($posts as $post) :
    echo "<pre>\n";
    echo "</pre>\n";
     endforeach; ?>

    Also, the $this->db->debug_query(); may not return what you want. I'd recommend the following after you run the query:

  • Interesting. That helps a lot. Thank you :)
    It's been a while since I worked in Fuel so just need to refresh my mind. I work in CI a lot, but Fuel is just different enough to forget the important parts :)

Sign In or Register to comment.