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
-~----------~----~----~----~------~----~------~--~---

Reply via email to