CakePHP's list problem
Posted
by jun
on Stack Overflow
See other posts from Stack Overflow
or by jun
Published on 2010-01-18T15:24:43Z
Indexed on
2010/04/28
10:33 UTC
Read the original article
Hit count: 406
Hi there.
I have this table in my DB:
Group
- ID-Name
- 1 -abc
- 2 -def
- 3 -ghi
Pages
- id-group_id-name
- 1 -1 -home
- 2 -1 -about us
Now I wanted to make a select box that groups them by 'group' using:
function add() {
$this->set('pages', $this->Page->find('list', array('fields' => array('Page.id', 'Page.name', 'Page.group_id'))));
}
In my add.ctp:
echo $form->input('group_id', array('options' => $pages));
The output:
<select name="data[Page][id]" id="PageId">
<optgroup label="1">
<option value="1">Home</option>
<option value="2">About Us</option>
</optgroup>
</select>
I wanted the optgroup to display the actual group name not the group id like:
<select name="data[Page][id]" id="PageId">
<optgroup label="abc">
<option value="1">Home</option>
<option value="2">About Us</option>
</optgroup>
</select>
I have tried this one:
$this->Page->find('list', array('conditions' => 'Group.id = Page.id', 'fields' => array('Page.id', 'Page.name', 'Group.name')));
But 'Group.id' and 'Group.name' is unknown.
Thanks!
© Stack Overflow or respective owner