@santino83: That should be, "... you should use find('list') to get a list ..."On Thu, Sep 17, 2009 at 7:10 AM, Thiago Nuic Vidigal <[email protected]> wrote: > teknoid has a post on his blog about a "superlist" that does what you want. > > > > On Wed, Sep 16, 2009 at 11:14 AM, santino83 <[email protected]> wrote: >> >> Hi, >> >> First of all you should use find('first') to get a list from your >> model. As you can read in http://book.cakephp.org/view/810/find-list, >> you could set $displayField in Model and tell to cake which field it >> should use as "description". In your case, it seems cake couldn't >> concatenate fields as description, so a solution could be >> >> 1) ovveride find in Model class >> 2) using a custom function >> >> In both cases, your function will retry all model records, and then >> create a list using some utilities. I use this: >> >> $results = $this->find('all', array( 'conditions' => ..., .. .. ) ); >> >> /* >> * Extract list, result: model_id => code+description >> */ >> return $results ? array_combine(Set::extract('/MODELNAME/id', >> $results), array_map(array($this,'getDescription'),$results) ) : >> null; >> >> and getDescription: >> >> private function getDescription($data){ >> return $data['MODELNAME']['code'].' '.$data['MODELNAME'] >> ['description']; >> } >> >> note: change MODELNAME rightly >> >> >> On Sep 16, 3:51 pm, Ernesto <[email protected]> wrote: >> > Hello. >> > >> > i have a model that's using a simple 3-columns table >> > >> > item_id >> > code >> > description >> > >> > i want to obtain a select box that shows the fields "code" and >> > "description" concatenated. >> > >> > right now i'm using a foreach loop >> > >> > foreach ($items as $key => $item) $selectArray[$key] = $item["code"] . >> > " - " . $item["description"]; >> > >> > is there any way to do this directly in the "find" call? >> >> > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
