Custom Finder not displaying in HTML-select

Hello guys!

I created a custom finder in UsersTable to find all Users associated to a specific Group. The finder works well so far. Now I also want to use the finder for filling a HTML-Select dropdown with that data, and here it fails.

The finder
public function findAdmins(Query $query, array $options) { return $query->matching('Groups', function($q) { return $q->where(['Groups.title' => 'Administrators']); }); }

The Controller-Action “add”
$lawyers = $this->Files->Users->find(‘Administrators’, [‘limit’ => 200])->toList();

The Result in HTML-Select Dropdown
1-Line-JSON-String of the whole object. e.g.:
entry no.1: {“id”:4,“username”:“admin”…}
entry no.2: {“id”:6,“username”:…}

Data as of DebugKit
admins(array)->4(array)->properties…
admins(array)->6(array)->properties…

Am I unable to use that finder for an html select? Do I really have to create a second one specific for html-selects?

Thanks in advance!

1 Like

HTML select generation requires either a simple array that looks like:

$options = [
  'key' => 'value'
]

Or a complex values that look like

$options = [
 ['value' => 'a', 'text' => 'Albatross'],
]

Your data doesn’t seem to be in either of those shapes. You’ll need to make it match one of these shapes, or re-implement the select widget to work with the data format you have.

Maybe this short code will work in your controller:

$lawyers = $this->Files->Users->find('list')->find('Administrators', ['limit' => 200]);

This will keep the find('list') format.