Adding a Category dropdown to an advanced module

edited January 2014 in Modules
I started working with FuelCMS a week ago, and now I'm trying to add the category feature to my module.

I added public $foreign_keys = array('category_id' => array(FUEL_FOLDER => 'fuel_categories_model')); at the top of my model class. It appears it is working as I now have a dropdown with my categories, however when I hit save the dropdown reverts back to the default "select one" option. I have no idea if the category was saved, and I don't see anything in the database as well.

Is there something I must do in the form_fields method?

Comments

  • edited 10:09AM
    Does your database table for you model have a field of "category_id" in it?
  • edited 10:09AM
    No, I don't. So I must create a category_id column in the table I want to use categories?
  • edited 10:09AM
    Ok thanks it worked.

    My next question is about displaying the category name in the list display. Currently it'll just show the category_id. Can I do a join query in the list_items method?
  • edited 10:09AM
    Sure. You can use any normal CI active record you want.
    function list_items($limit = NULL, $offset = NULL, $col = 'name', $order = 'desc', $just_count = FALSE) { $this->db->join('fuel_categories', 'fuel_categories.id = category_id', 'left'); $this->db->select('my_table.id fuel_categories.name as category, my_table.publish); return parent::data($limit, $offset, $col, $order, $just_count); }
Sign In or Register to comment.