The sections are related to the level and degree. So I need to show on the field select level, grade and section. Reading the cakephp 3 book found that using "valueField" I can show the field I want. But this time I need to show two fields.
In my controller:
$secciones = $this->Users->Secciones->find('list', [
'keyField' => 'id',
'valueField' => ['nivele.nivel']
])->contain(['Niveles', 'Grados']);
When I put in the valueField ['nivele.nivel','grado.grado'] only show a semicolon.
How can display two relationship in the select field?
Thanks.
I readed the solution in How do I create a keyValue pair by combining/having two fields in CakePHP 3? but in that case no relation. In my case i need to use two fields with relation.
Reading the solution in How do I create a keyValue pair by combining/having two fields in CakePHP 3? I did this:
$secciones = $this->User->Secciones
->find()
->select(['id', 'nivele_id', 'grado_id'])
->formatResults(function($results) {
/* @var $results \Cake\Datasource\ResultSetInterface|\Cake\Collection\CollectionInterface */
return $results->combine(
'id',
function($row) {
return $row['nivele.nivel'] . ' ' . $row['grado.grado'];
}
);
})
->contain(['Niveles', 'Grados']);
But I have a fatal error :-(