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 1:13PM
    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 1:13PM
    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 1:13PM
    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 1:13PM
    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 1:13PM
    Ah ha, thank you so very much it's been proper doing my head in. Sterling support from a sterling product!!!!
  • edited 1:13PM
    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 1:13PM
    If you change the "display_field" parameter to the field you want used instead, it should change that value as well.
  • edited 1:13PM
    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 1:13PM
    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 1:13PM
    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 1:13PM
    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 1:13PM
    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.