Dropdown value for related database

I baked an application based on these two tables


  • id
  • title
  • person_id


  • id
  • name

when I now create a bookmark I have a dropdown to chose the person but instead of seeing the names I see the ids.
How can I change it to see the names

echo $this->Form->control(‘person_id’, [‘options’ => $persons]);

$persons = $this->Bookmarks->Persons->find(‘list’, [‘limit’ => 200]);

Thank you very much

1 Like

In view file currently its $person=> Id you have to pass $ person=>Name

This is what you should do.

In your src/Model/Table/PersonsTable.php , in the initialize(), add the following if it is not there:


// Prior to 3.4.0

So when you call

$persons = $this->Bookmarks->Persons->find(‘list’, [‘limit’ => 200]);
$data = $persons->toArray();
$data = [1 => ‘Person 1 Name’, 2 => ‘Person 2 Name’]
You will have an array similar as below:

Details here - https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#finding-key-value-pairs

1 Like

Thanks, the change did exaclty what I was looking!