Re: concatenation in find('list')

2008-10-28 Thread teknoid

To keep your controllers skinny, the following approach (using pretty
much the same method does the trick):
http://teknoid.wordpress.com/2008/09/04/findlist-with-three-or-combined-fields/

Also, once you retrive the results and set them to a certain variable
in the controller, there is no need to pass the array to the view.
CakePHP will handle it for you... (another shameless self-promo :) )
http://teknoid.wordpress.com/2008/08/08/automagical-selects-or-checkboxes/


On Oct 28, 9:29 am, "Liebermann, Anja Carolin"
<[EMAIL PROTECTED]> wrote:
> Hi Mario,
>
> I have similar situations in my application and I guess there is no automatic 
> way to do it.
>
> So what I do is get the data wth all fields and loop through them and create 
> another array with value = id and shown sring firstname + family name.
>
> If there is a more elegant solution I don't know it.
>
> Anja
>
> -Ursprüngliche Nachricht-
> Von: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Im Auftrag von mario
> Gesendet: Sonntag, 26. Oktober 2008 16:09
> An: CakePHP
> Betreff: concatenation in find('list')
>
> Hi guys,
>
> I have this following code snippet from my controller:
>
> $salespeople = $this->Campaign->Salesperson->find('list',
>                                   array('order' => 'Salesperson.firstname 
> ASC',
>                                           'fields' => array('Salesperson.id', 
> 'Salesperson.firstname')));
>
> In my view, I have this following line:
>
> echo $form->input('salesperson_id');
>
> This codes would create a combobox in my view that would have a key: 
> salesperson.id and value: salesperson.firstname
>
> Now here is what I want to do:
>
> I also have a field 'lastname' under my salespeople table and I want it to be 
> concatenated to the salespersons'
> firstname (with a space between the firstname and lastname).
>
> I can't just have the firstname in my combobox because there is a high 
> possibility that there would be duplicates for firstnames.
> It would be better if firstname and lastname would be displayed in my view's 
> combobox and still would match to a corresponding salesperson.id.
>
> Is there a way to do this?
>
> Thanks,
> Mario
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: concatenation in find('list')

2008-10-28 Thread Samuel DeVore

The way I do it based on http://c7y.phparch.com/c/entry/1/art,mvc_and_cake and
http://www.pseudocoder.com/archives/2008/10/24/cakephp-custom-find-types/

I add to my app_model.php file (as per Matt's article)

function find($type, $options = array()) {
  $method = null;
  if(is_string($type)) {
$method = sprintf('__find%s', Inflector::camelize($type));
  }

  if($method && method_exists($this, $method)) {
return $this->{$method}($options);
  } else {
return parent::find($type, $options);
  }
}

Then I can create custom find types in models that need them, like in
my User model I have

function __findNames($options = array()) {
$users = $this->find('all', array(
'fields'=>array('id','last_name','first_name'),

'order'=>array('last_name','first_name'),'recursive'=>-1));
$users = Set::combine($users, 
'{n}.User.id',array('%s
%s','{n}.User.first_name','{n}.User.last_name'));
return $users;

}   

which then  I can call when I need it like

$usersListForSelectMenu = $this->Dingus->User->find('names',array
(stuff in here))





On Tue, Oct 28, 2008 at 6:43 AM, mario <[EMAIL PROTECTED]> wrote:
>
> Thanks. But Chad's suggestion works fine for me.
> I suggest you also try it. =)
>
>
> On Oct 28, 6:29 am, "Liebermann, Anja Carolin"
> <[EMAIL PROTECTED]> wrote:
>> Hi Mario,
>>
>> I have similar situations in my application and I guess there is no 
>> automatic way to do it.
>>
>> So what I do is get the data wth all fields and loop through them and create 
>> another array with value = id and shown sring firstname + family name.
>>
>> If there is a more elegant solution I don't know it.
>>
>> Anja
>>
>> -Ursprüngliche Nachricht-
>> Von: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Im Auftrag von mario
>> Gesendet: Sonntag, 26. Oktober 2008 16:09
>> An: CakePHP
>> Betreff: concatenation in find('list')
>>
>> Hi guys,
>>
>> I have this following code snippet from my controller:
>>
>> $salespeople = $this->Campaign->Salesperson->find('list',
>>   array('order' => 'Salesperson.firstname 
>> ASC',
>>   'fields' => 
>> array('Salesperson.id', 'Salesperson.firstname')));
>>
>> In my view, I have this following line:
>>
>> echo $form->input('salesperson_id');
>>
>> This codes would create a combobox in my view that would have a key: 
>> salesperson.id and value: salesperson.firstname
>>
>> Now here is what I want to do:
>>
>> I also have a field 'lastname' under my salespeople table and I want it to 
>> be concatenated to the salespersons'
>> firstname (with a space between the firstname and lastname).
>>
>> I can't just have the firstname in my combobox because there is a high 
>> possibility that there would be duplicates for firstnames.
>> It would be better if firstname and lastname would be displayed in my view's 
>> combobox and still would match to a corresponding salesperson.id.
>>
>> Is there a way to do this?
>>
>> Thanks,
>> Mario
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: concatenation in find('list')

2008-10-28 Thread mario

Thanks. But Chad's suggestion works fine for me.
I suggest you also try it. =)


On Oct 28, 6:29 am, "Liebermann, Anja Carolin"
<[EMAIL PROTECTED]> wrote:
> Hi Mario,
>
> I have similar situations in my application and I guess there is no automatic 
> way to do it.
>
> So what I do is get the data wth all fields and loop through them and create 
> another array with value = id and shown sring firstname + family name.
>
> If there is a more elegant solution I don't know it.
>
> Anja
>
> -Ursprüngliche Nachricht-
> Von: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Im Auftrag von mario
> Gesendet: Sonntag, 26. Oktober 2008 16:09
> An: CakePHP
> Betreff: concatenation in find('list')
>
> Hi guys,
>
> I have this following code snippet from my controller:
>
> $salespeople = $this->Campaign->Salesperson->find('list',
>                                   array('order' => 'Salesperson.firstname 
> ASC',
>                                           'fields' => array('Salesperson.id', 
> 'Salesperson.firstname')));
>
> In my view, I have this following line:
>
> echo $form->input('salesperson_id');
>
> This codes would create a combobox in my view that would have a key: 
> salesperson.id and value: salesperson.firstname
>
> Now here is what I want to do:
>
> I also have a field 'lastname' under my salespeople table and I want it to be 
> concatenated to the salespersons'
> firstname (with a space between the firstname and lastname).
>
> I can't just have the firstname in my combobox because there is a high 
> possibility that there would be duplicates for firstnames.
> It would be better if firstname and lastname would be displayed in my view's 
> combobox and still would match to a corresponding salesperson.id.
>
> Is there a way to do this?
>
> Thanks,
> Mario
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



AW: concatenation in find('list')

2008-10-28 Thread Liebermann, Anja Carolin

Hi Mario,

I have similar situations in my application and I guess there is no automatic 
way to do it.

So what I do is get the data wth all fields and loop through them and create 
another array with value = id and shown sring firstname + family name.

If there is a more elegant solution I don't know it.

Anja


-Ursprüngliche Nachricht-
Von: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Im Auftrag von mario
Gesendet: Sonntag, 26. Oktober 2008 16:09
An: CakePHP
Betreff: concatenation in find('list')


Hi guys,

I have this following code snippet from my controller:

$salespeople = $this->Campaign->Salesperson->find('list',
  array('order' => 'Salesperson.firstname ASC',
  'fields' => array('Salesperson.id', 
'Salesperson.firstname')));


In my view, I have this following line:

echo $form->input('salesperson_id');


This codes would create a combobox in my view that would have a key: 
salesperson.id and value: salesperson.firstname


Now here is what I want to do:

I also have a field 'lastname' under my salespeople table and I want it to be 
concatenated to the salespersons'
firstname (with a space between the firstname and lastname).

I can't just have the firstname in my combobox because there is a high 
possibility that there would be duplicates for firstnames.
It would be better if firstname and lastname would be displayed in my view's 
combobox and still would match to a corresponding salesperson.id.

Is there a way to do this?


Thanks,
Mario


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: concatenation in find('list')

2008-10-26 Thread chad

This is probably what your looking for...

[controller]
$salespeople = $this->Campaign->Salesperson->find('all',
array('order'=>'Salesperson.firstname ASC', 'fields' =>
'Salesperson.id, Salesperson.firstname, Salesperson.lastname'));
$salespeople = Set::combine($salespeople, '{n}.Salesperson.id',
array('%s %s', '{n}.Salesperson.firstname', 'Salesperson.lastname'));
$this->set('salespeople', $salespeople);

[view]
echo $form->select('Salesperson.id', array($salespeople), null,
array(), '-Please Select-');


On Oct 26, 11:09 am, mario <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I have this following code snippet from my controller:
>
> $salespeople = $this->Campaign->Salesperson->find('list',
>                                   array('order' =>
> 'Salesperson.firstname ASC',
>                                           'fields' =>
> array('Salesperson.id', 'Salesperson.firstname')));
>
> In my view, I have this following line:
>
> echo $form->input('salesperson_id');
>
> This codes would create a combobox in my view
> that would have a key: salesperson.id and value: salesperson.firstname
>
> Now here is what I want to do:
>
> I also have a field 'lastname' under my salespeople table
> and I want it to be concatenated to the salespersons'
> firstname (with a space between the firstname and lastname).
>
> I can't just have the firstname in my combobox because there is
> a high possibility that there would be duplicates for firstnames.
> It would be better if firstname and lastname would be displayed
> in my view's combobox and still would match to a corresponding
> salesperson.id.
>
> Is there a way to do this?
>
> Thanks,
> Mario
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: concatenation in find('list')

2008-10-26 Thread chad

oops. add {n}. before Salesperson.lastname in the Set::combine
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



concatenation in find('list')

2008-10-26 Thread mario

Hi guys,

I have this following code snippet from my controller:

$salespeople = $this->Campaign->Salesperson->find('list',
  array('order' =>
'Salesperson.firstname ASC',
  'fields' =>
array('Salesperson.id', 'Salesperson.firstname')));


In my view, I have this following line:

echo $form->input('salesperson_id');


This codes would create a combobox in my view
that would have a key: salesperson.id and value: salesperson.firstname


Now here is what I want to do:

I also have a field 'lastname' under my salespeople table
and I want it to be concatenated to the salespersons'
firstname (with a space between the firstname and lastname).

I can't just have the firstname in my combobox because there is
a high possibility that there would be duplicates for firstnames.
It would be better if firstname and lastname would be displayed
in my view's combobox and still would match to a corresponding
salesperson.id.

Is there a way to do this?


Thanks,
Mario
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---