CakePHP's list problem

ritz

New Member
I have this table in my DB:\[code\]Group - ID-Name - 1 -abc - 2 -def - 3 -ghiPages - id-group_id-name - 1 -1 -home - 2 -1 -about us\[/code\]Now I wanted to make a select box that groups them by 'group' using:\[code\]function add() {$this->set('pages', $this->Page->find('list', array('fields' => array('Page.id', 'Page.name', 'Page.group_id'))));}\[/code\]In my add.ctp:\[code\]echo $form->input('group_id', array('options' => $pages));\[/code\]The output:\[code\]<select name="data[Page][id]" id="PageId"><optgroup label="1"><option value="http://stackoverflow.com/questions/2087018/1">Home</option><option value="http://stackoverflow.com/questions/2087018/2">About Us</option></optgroup></select>\[/code\]I wanted the optgroup to display the actual group name not the group id like:\[code\]<select name="data[Page][id]" id="PageId"><optgroup label="abc"><option value="http://stackoverflow.com/questions/2087018/1">Home</option><option value="http://stackoverflow.com/questions/2087018/2">About Us</option></optgroup></select>\[/code\]I have tried this one:\[code\]$this->Page->find('list', array('conditions' => 'Group.id = Page.id', 'fields' => array('Page.id', 'Page.name', 'Group.name')));\[/code\]But 'Group.id' and 'Group.name' is unknown.Thanks!
 
Back
Top