Populating drop down list in FUEL CMS Edit page

edited September 2013 in Modules
Hi there

I have a table which is a joining table for several others. How do I display the correct join parameter in the the select drop down in the edit page within the advance module CMS where is says 'Select another'?

At the moment it's just displaying the row id which is not what I want.

Any guidance would be very much appreciated.

Peace, love and flowers...

Comments

  • edited 4:33AM
    Hmmm, after a bit of fiddling about I would assume that this is related to the display_field parameter of module configuration, but how would I change this to refer to a joined table?
  • edited 4:33AM
    Is that dropdown select being automatically generated by a "foreign_key" property on the model? If so, you can overwrite that fields parameters in the form_fields method on your model. The example below is manually setting the values, however, if you have a method that generates a key/value array with the keys as the ID value and the value of the array as the label to be displayed in the dropdown, you can use that:
    public function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); $fields['my_select_field']['options'] = array(1 => 'value1', 2 => 'value2'); return $fields; }
  • edited 4:33AM
    Hi Mr Admin,

    Thanks for getting back to me so promptly, really appreciated!

    I'm referring to the actual default 'Select another' option that appears in the Fuel CMS admin interface in the same row as the 'Save', 'Unpublish' etc, etc buttons...

    Cheers!
  • edited 4:33AM
    Oh... in that case, you can overwrite the "get_others" method that's inherited from the base_module_model.php file. By default, it returns an array of key/value pairs from the current module's table.
  • edited 4:33AM
    Ah ha, thank you so very much it's been proper doing my head in. Sterling support from a sterling product!!!!
  • edited 4:33AM
    Fabulous, I'm managed to implement what I required.

    One final query relating to this, how do I similarly update the selected name in the breadcrumbs trail at the top of the page:

    Model name > Record being edited

    ...it currently it defaults to the first field with content, (I think as defined by display_field parameter in the module config).
  • edited 4:33AM
    If you change the "display_field" parameter to the field you want used instead, it should change that value as well.
  • edited 4:33AM
    Thanks for getting back to me again oh guru of all things Fuel.

    The field I want to use it joined to the model table, how would I reference that in the display field?

    Cheers!
  • edited 4:33AM
    You can use normal CI active record in your models so something like this may work:
    $this->db->join('my_table', 'my_table.id = my_other_table.id', 'left');
  • edited 4:33AM
    Thanks for your ongoing patience...

    I've done all the joins as required in my module, but how do I reference them in the xxxx/config/xxxx_fuel_modules.php file?

    $config['modules']['xxxx'] = array(
    'display_field' => 'joined_table_field_I_want_to_reference'
    );

    Sorry if I'm not being too clear!
  • edited 4:33AM
    Is this a join you want made for all "find_" queries? If so, you can add both a "select" and a "join" to the _common_query() method like so:
    function _common_query() { parent::_common_query(); $this->db->select('my_table.*, my_other_table.id as other_id'); $this->db->join('my_table', 'my_table.id = my_other_table.id', 'left'); }
  • edited 4:33AM
    Ah ha, so that I can reference the joined table name field using the common_query mehod - genius!

    I will let you know how I get on...

    Cheers!
Sign In or Register to comment.