<select> エレメントを生成するfind('list')を使う際に、出力する値を配列にしたい場合。
キー/値のペア出力
SampleController.php
$query = $articles->find('list', [
'keyField' => 'slug',
'valueField' => 'title'
]);
$data = $query->toArray();
参考:https://book.cakephp.org/3/ja/orm/retrieving-data-and-resultsets.html
キー/値(配列)のペア出力
SampleController.php
$query = $articles->find('list', [
'keyField' => 'slug',
'valueField' => function ($entity){
return [
'id' => $entity->id,
'title' => $entity->title,
];}
]);
$data = $query->toArray();