JGuiher
1
I have this in my controller:
$list = $this->Categories->find('children', ['for' => 7, 'fields' => 'name']);
$this->set(compact('categories', 'list'));
$this->set('_serialize', ['categories']);
and this in my view:
echo $this->Form->control('parent_id', ['options' => $list]); ?>
For some reason, the displayed text is JSON like this:
{ "name": "Billy" }
I have no idea what I am doing wrong, all my other stuff outputs normal.
raul338
2
You have to call toArray at the end of the chain
JGuiher
3
If I change to this, it still doesn’t fix it.
$query = $this->Categories->find('children', ['for' => 7, 'fields' => 'name']);
$list = $query->toArray();
raul338
4
instead of field name, you should use the list finder, and then to array
JGuiher
5
I don’t understand or something, because I try this and it gives me the whole row in JSON.
$list = $this->Categories->find('children', ['for' => 7, 'finder' => 'name'])->toArray();
Do you mean create my own finder method?
JGuiher
7
That works, but if I change it from list to children, it goes back to being a json response with the full row.
raul338
8
You can chain it
$list = $this->Categories
->find('children', ['for' => 7])
->find('list')
->toArray();
JGuiher
9
Thank you, that did it. Sorry I’m new to this, big learning curve for me.