Re: automagic select boxes for belongsto relations

2010-04-27 Thread WebbedIT
If concatenating or calculating fields etc. you will then need to use
Set::combine to reformat the array so the form helper can use it.

$data = $this-Artist-find(
   'all',
   array(
 'fields' = array(
concat(Artist.first_name,' ',Artist.last_name) as name
 )
   )
);

Would then need the following to set the array in the right format:

$this-set('artists', Set::combine($data, '{n}.Artist.id', '{n}.
0.name'));

HTH

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: automagic select boxes for belongsto relations

2010-04-27 Thread mrnnn
Thanks to both of you, you've been of great help! Really appreciate
it!

On Apr 27, 10:39 am, WebbedIT p...@webbedit.co.uk wrote:
 If concatenating or calculating fields etc. you will then need to use
 Set::combine to reformat the array so the form helper can use it.

 $data = $this-Artist-find(
    'all',
    array(
      'fields' = array(
         concat(Artist.first_name,' ',Artist.last_name) as name
      )
    )
 );

 Would then need the following to set the array in the right format:

 $this-set('artists', Set::combine($data, '{n}.Artist.id', '{n}.
 0.name'));

 HTH

 Paul

 Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
 their CakePHP related questions.

 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 
 athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


automagic select boxes for belongsto relations

2010-04-26 Thread mrnnn
hi all!

i'm merely beginning with cakephp and i've tried the two examples and
all worked fine.

but now i'm trying to convert my own sql scheme to a cake application
using the bake all command.

in short, the fields that matter:

artitsts {
 auto_increment int id
 first_name varchar(100)
 last_name varchar(100)
}

work {
 auto_increment id
 int artist_id
}

basically, what i'd like is that, when editing/adding a work, you'd
get a select box to select the artist. now, when i bake, it either:
-gives me no select box, just an input field
-sometimes i get to select the artist id

what i want: a select box with a combination of the first and last
name.

is there magic to this or should i just do it manually? fill an array
in the controller, push it to the view and then make a $form-select
element? or is there a way to obtain the behaviour of the example,
where creating a user shows a select box for the group, even though
the view says $form-input?

the only difference i see so far is that the group name is unique.
should i make my lastname column unique maybe? or can i make the
combination unique? that probably won't work, will it?

or is it the name of the column? does cakephp automatically pick the
name field if present?

thanks!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: automagic select boxes for belongsto relations

2010-04-26 Thread dreamingmind
$this-Artist-find('list') is going get you part of the way there.
find('list') will use id for the array index (and the select value
attribute). It will want to default to the field 'name' or 'title' for
the value. This can be changed as you can see in the documentation for
find(). Getting the names concatenated is a bit trickier. I'm still
working it out myself but I'm 90% sure it's possible.

Though you can (incredibly) do this:

$this-Artist-find(
   'all',
   array(
 'fields' = array(
concat(Artist.first_name,' ',Artist.last_name) as name
 )
   )
);

to retrieve your concatenated name.

You can also specify the two fields to use in find('list') in the same
array(fields(array()) structure. However I haven't been successful in
getting a concatenation in the 'list' variant. It seems possible
though. Probably I just keep making errors in my code.

Don


On Apr 26, 7:02 am, mrnnn marijn.vandevoo...@gmail.com wrote:
 hi all!

 i'm merely beginning with cakephp and i've tried the two examples and
 all worked fine.

 but now i'm trying to convert my own sql scheme to a cake application
 using the bake all command.

 in short, the fields that matter:

 artitsts {
  auto_increment int id
  first_name varchar(100)
  last_name varchar(100)

 }

 work {
  auto_increment id
  int artist_id

 }

 basically, what i'd like is that, when editing/adding a work, you'd
 get a select box to select the artist. now, when i bake, it either:
 -gives me no select box, just an input field
 -sometimes i get to select the artist id

 what i want: a select box with a combination of the first and last
 name.

 is there magic to this or should i just do it manually? fill an array
 in the controller, push it to the view and then make a $form-select
 element? or is there a way to obtain the behaviour of the example,
 where creating a user shows a select box for the group, even though
 the view says $form-input?

 the only difference i see so far is that the group name is unique.
 should i make my lastname column unique maybe? or can i make the
 combination unique? that probably won't work, will it?

 or is it the name of the column? does cakephp automatically pick the
 name field if present?

 thanks!

 Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
 their CakePHP related questions.

 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 
 athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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