Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Noob here - Why doesn't fuel_model show anything from my simple module database?

edited November 2019 in Modules

I've made a simple module names 'stories' using this syntax on the command line:
php index.php fuel/generate/simple stories

I've made an entry in the CMS in the stories module and wanted to display the title of each story added.

Here is my code within a static view file, which shows fuel_model giving an empty array, and an alternative method of retrieving my db information:

<?php $stories = fuel_model('stories'); //this shows an empty array foreach ($stories as $value){ echo $value['title']."<br />".$value['content']."<br /><br />"; } $stories2 = $this->stories_model->list_items(); //this works foreach ($stories2 as $value){ echo $value['title']."<br />".$value['content']."<br /><br />"; } echo "<br />"; echo "<br />"; var_dump($stories); //this shows an empty array echo "<br />"; var_dump($stories2); //this works ?>

I thought I should be using fuel_model() to get stuff from the module...
Please help!


  • $stories = $this->stories->find_all();
    Should give you an array that you can work with ( foreach() )

  • I tried what you said, and it also outputs an empty array. What am I missing? I've tried following the docs, and can't quite seem to make sense of why my default module won't work. I've made no modifications to the generated simple module.

    I do have 2 'stories' entered on the admin side, and they list fine (on the admin side). Your $stories = $this->stories->find_all(); only gives an error, where $stories = $this->stories_model->find_all(); will output the blank array, same as the fuel_model('stories');

    list_all() does work though and it appears that this is the function I should use for the view file? Sorry if I'm missing something obvious.

  • Does the "stories" table have a "published" or "active" field? If so, is it set to "yes". By default, FUEL will look at those to fields to automatically not include those in the query. Similar with "publish_date". You can do this->stories_model->debug_query() to output the raw SQL being generated after the last request which may help you debug too.

  • Thank-you so much, that was it! I didn't realize find_all() needed a pubdate, and only had the published field enabled. Once I set a pubdate, and ensured published was still active, the find_all() worked and output my fields. It also works with fuel_model('stories_module') as well.

Sign In or Register to comment.