Select from db in list_items doesn't appear to do anything

edited January 2013 in Modules
I downloaded FUEL a few days ago and have been reading through the User Guide and some tutorials. Today I started to work through the 'Creating Simple Modules' tutorial (http://www.getfuelcms.com/user_guide/modules/tutorial) to get a feel for how everything works. I changed it a little bit as I worked through to be a gallery that has artists and art work and it was all going well until I realized the form wasn't in quite the right order. I couldn't figure out why so I went back to a clean install and this time followed the tutorial exactly, copying and pasting the SQL and php.

I got down to 'Setting Up the Form' in the 'The Articles Module' section and found I had the same issue. When I go to the Create Article in the admin panel I get a form field for 'Permalink' which from the select and from the screenshot I don't think I should. I feel like I'm bashing my head against a wall trying to figure out what's wrong, commenting out the select doesn't appear to change anything at all and I'm getting more confused by the minute. It must be something simple I'm missing but I can't find anyone else who's had the same problem. If anyone could help it would be much appreciated.

Articles class:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Articles_model extends Base_module_model { public $foreign_keys = array('author_id' => 'authors_model'); public $parsed_fields = array('content', 'content_formatted'); function __construct() { parent::__construct('articles'); // table name } function list_items($limit = NULL, $offset = NULL, $col = 'name', $order = 'asc') { $this->db->join('authors', 'authors.id = articles.author_id', 'left'); $this->db->select('articles.id, authors.name AS author, title, SUBSTRING(content, 1, 50) AS content, date_added, articles.published', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function form_fields($values = array()) { $fields = parent::form_fields($values); // ******************* ADD CUSOM FORM STUFF HERE ******************* return $fields; } } class Article_model extends Data_record { }

Thank you

Comments

  • edited 10:36PM
    Hey Emma,

    And you are viewing the form under the fuel/articles? Also, does the database table it's referencing have that field in it and do the other fields match up to what is represented in the database table.

    If you are just starting out, I'd recommend trying out the 1.0 beta which contains a lot of new features as well as the ability to create model relationship like has_many and belongs to without the need for relationship tables:
    https://github.com/daylightstudio/FUEL-CMS/tree/1.0
  • edited 10:36PM
    Hey, thanks for the reply, I will have a look at the beta.

    I am viewing it under fuel/articles/create, it seems to be displaying all the fields that are in the database except 'id' and 'date_added'. This is my database:
    image

    And this is the form it's showing:
    image

    Still with the same model I posted above. I also added another field in the db called 'test', the model remained unchanged and the form still displayed it
  • edited 10:36PM
    Hmm. I guess I'm not sure I understand the current problem. What I see in the screenshot looks correct based on what I see in the table. If an additional field is added to the table, I would see that additional field appear in the form. The ID and date_added are automatically hidden by default in FUEL. You can overwrite any of the form fields though through the form_fields method. That method should return an array of fields which gets used by the Form_builder class to generate the fields. Example of changing the title field to a bigger text area field:
    function form_fields($values = array()) { $fields = parent::form_fields($values); $fields['title']['type'] = 'textarea'; return $fields; }
  • edited 10:36PM
    Hm, then I'm not sure what the select is actually supposed to do. If I change this line:

    $this->db->select('articles.id, authors.name AS author, title, SUBSTRING(content, 1, 50) AS content, date_added, articles.published', FALSE);

    I thought it would change what was selected from the database, but it doesn't do anything. This is the tutorial screenshot:

    http://www.getfuelcms.com/fuel/modules/user_guide/assets/images/examples/articles_form.png

    And you can see it differs from my screenshot because it doesn't have the 'Permalink' field. What is making that not show if it isn't the select?

    Thank you for being patient, hopefully that explains a bit better what I'm confused on.
  • edited 10:36PM
    The list_items method is what is used for rendering the list view of all records (the first page when you go to the module) and is not used for the dropdown. If you want to overwrite that dropdown you can try something like the following:
    function form_fields($values = array()) { $fields = parent::form_fields($values); $fields['author_id']['options'] = array('1' => 'Me'); // this just needs to be an associative array value return $fields; }
    Or you could try overwriting the model's list_options method, which is inherited from the MY_Model class.
  • edited 10:36PM
    Ah okay, thank you for explaining that. I realize now it's the $hidden_fields array or setting the type like you suggested that I needed to make it look the same. I knew it would be something simple, I was just misunderstanding what list_items was for.

    Thank you for the help =D
Sign In or Register to comment.