@brian:

find('list') doesn't allow you to concatenate fields, because you  
don't have all the fields you need. Think you have a model, like id- 
name-lastname user, and you want back from db a list of all user like

id => name+lastname

you cannot use find('list'). First of all, you need find('all') and  
then create by yourself the final list, like I wrote below

On 17/set/2009, at giovedì 17 settembre 18:33, brian wrote:

>
> @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 <tvidi...@gmail.com 
> > 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 <giosa...@gmail.com>  
>> 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 <e.fanz...@gmail.com> 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to