Re: Automagic Form (Drop down list)

2010-06-16 Thread euromark
good idea :)

@leo
i think its supposed to be in the view - in contradiction to the
default value.
but as with many things - it comes down to personal preferation in the
end


On 16 Jun., 17:27, Shaz  wrote:
> Whoa! So much info! Thanks all; beginning to like cake more and more
> day by day.
>
> I settled for using $displayField in the model; am trying to keep the
> controller as skinny as possible.

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 Form (Drop down list)

2010-06-16 Thread Shaz
Whoa! So much info! Thanks all; beginning to like cake more and more
day by day.

I settled for using $displayField in the model; am trying to keep the
controller as skinny as possible.

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 Form (Drop down list)

2010-06-16 Thread leo
> usually you dont pass the dummy field via controller
> there is an empty field param for it
>
> echo $this->Form->input('category_id', array('options'=>$cats,
> 'empty=>'dummyName');

I prefer to handle this kind of logic in the controller.

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 Form (Drop down list)

2010-06-15 Thread euromark
and last but not least
if you want to set default values - this is NOT done in the views
many make that mistake

this is actually done in the controller

if (!empty($this->data)) {
...
} else {
 // set default values here
$this->data['Model']['field'] = 'defautlValue';
}

this way after a post and some validation errors the defaults dont
override any chances

otherwise they would always jump back to default - which is really
annoying for users


On 15 Jun., 19:25, calvin  wrote:
> And also, if you have a nonstandard display field that isn't just
> being used for this particular select input, then you will probably
> want to set the $displayField property in your model so cake can
> automagically display that field in find('list') results and in
> tables.
>
> On Jun 15, 8:46 am, euromark  wrote:
>
>
>
> > usually you dont pass the dummy field via controller
> > there is an empty field param for it
>
> > echo $this->Form->input('category_id', array('options'=>$cats,
> > 'empty=>'dummyName');
> > or
> > echo $this->Form->input('category_id', array('options'=>$cats,
> > 'empty=>array('dummyFieldValue'=>'dummyName')));
>
> > On 15 Jun., 17:35, leo  wrote:
>
> > > You might also want to do this if you want to specify which fields to
> > > return:
> > > $this->set('categories', $this->Item->Category-
>
> > > >find('list',array('fields'=>array('id','other_name'));
>
> > > If you need to add a dummy field, try:
> > > $categories = array(0=>'unassigned') + 
> > > $this->Item->Category->find('list',array('fields'=>array('id','other_name')
> > >  );
>
> > > $this->set('categories', $categories);
>
> > > And in the view, if your categories aren't appearing (because the
> > > naming is different) try:
> > > echo $this->Form->input('category_id',array('options'=>$cats));

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 Form (Drop down list)

2010-06-15 Thread calvin
And also, if you have a nonstandard display field that isn't just
being used for this particular select input, then you will probably
want to set the $displayField property in your model so cake can
automagically display that field in find('list') results and in
tables.

On Jun 15, 8:46 am, euromark  wrote:
> usually you dont pass the dummy field via controller
> there is an empty field param for it
>
> echo $this->Form->input('category_id', array('options'=>$cats,
> 'empty=>'dummyName');
> or
> echo $this->Form->input('category_id', array('options'=>$cats,
> 'empty=>array('dummyFieldValue'=>'dummyName')));
>
> On 15 Jun., 17:35, leo  wrote:
>
> > You might also want to do this if you want to specify which fields to
> > return:
> > $this->set('categories', $this->Item->Category-
>
> > >find('list',array('fields'=>array('id','other_name'));
>
> > If you need to add a dummy field, try:
> > $categories = array(0=>'unassigned') + 
> > $this->Item->Category->find('list',array('fields'=>array('id','other_name'));
>
> > $this->set('categories', $categories);
>
> > And in the view, if your categories aren't appearing (because the
> > naming is different) try:
> > echo $this->Form->input('category_id',array('options'=>$cats));

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 Form (Drop down list)

2010-06-15 Thread euromark
usually you dont pass the dummy field via controller
there is an empty field param for it

echo $this->Form->input('category_id', array('options'=>$cats,
'empty=>'dummyName');
or
echo $this->Form->input('category_id', array('options'=>$cats,
'empty=>array('dummyFieldValue'=>'dummyName')));


On 15 Jun., 17:35, leo  wrote:
> You might also want to do this if you want to specify which fields to
> return:
> $this->set('categories', $this->Item->Category-
>
> >find('list',array('fields'=>array('id','other_name'));
>
> If you need to add a dummy field, try:
> $categories = array(0=>'unassigned') + 
> $this->Item->Category->find('list',array('fields'=>array('id','other_name'));
>
> $this->set('categories', $categories);
>
> And in the view, if your categories aren't appearing (because the
> naming is different) try:
> echo $this->Form->input('category_id',array('options'=>$cats));

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 Form (Drop down list)

2010-06-15 Thread leo
You might also want to do this if you want to specify which fields to
return:
$this->set('categories', $this->Item->Category-
>find('list',array('fields'=>array('id','other_name'));

If you need to add a dummy field, try:
$categories = array(0=>'unassigned') + $this->Item->Category-
>find('list',array('fields'=>array('id','other_name'));
$this->set('categories', $categories);

And in the view, if your categories aren't appearing (because the
naming is different) try:
echo $this->Form->input('category_id',array('options'=>$cats));

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 Form (Drop down list)

2010-06-15 Thread leo
You might also want to do this if you want to specify which fields to
return:
$this->set('categories', $this->Item->Category-
>find('list',array('fields'=>array('id','other_name'));

If you need to add a dummy field, try:
$categories = array(0=>'unassigned') + $this->Item->Category-
>find('list',array('fields'=>array('id','other_name'));
$this->set('categories', $categories);

And in the view, if your categories aren't appearing (because the
naming is different) try:
echo $this->Form->input('category_id',array('options'=>$cats));

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 Form (Drop down list)

2010-06-15 Thread Jeremy Burns | Class Outfit
Let's assume that you are working with Items, each of which is in a category - 
so you need a Category drop down.

In the items_controller action that calls your form, do the following:

$this->set('categories', $this->Item->Category->find('list');

In your view, type this:

echo $this->Form->input('category_id');

Cake will automatically tie up your $categories variable (created by 
this->set('categories', etc...) and use it as the option list for the drop 
down. The stored value will be 'id', the displayed value will be 'name'. This 
does - of course - assume that you have adhered to Cake's table and field 
naming conventions.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 15 Jun 2010, at 14:00, Shaz wrote:

> Probably something really simple but I can't figure it out / find
> information on it:
> 
> Got a form (add article) with a drop down list (categories). How do I
> get it to show the category names rather than id while still
> maintaining the id as the value?
> 
> 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

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 Form (Drop down list)

2010-06-15 Thread Shaz
Probably something really simple but I can't figure it out / find
information on it:

Got a form (add article) with a drop down list (categories). How do I
get it to show the category names rather than id while still
maintaining the id as the value?

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