Wednesday, November 26, 2008

Re: Help with populating SELECT drop down

@Alexandre C.

I tried your code but all I got is one field from database table: id
My debug array looks like this:
[1]=> 1
[3]=> 3

And what I need is:

[1] => array(sex=>male,size=>L)

I found something about using your method and then set::combine or
something similar but this seems too complicated regarding to a nice
simple solution with foreach($productVariant as $variant) bla...bla

In other posts abou this they mentioned depreciated method
generateList that would take other fields from database. So, it was
something like combination of: find('all') and set::extract.. or so

thank you for your precious time.

You've been most helpful :)

On Nov 21, 1:15 pm, Alexandru Ciobanu <ics.cake...@gmail.com> wrote:
> luigi7up wrote:
> > @anja
> > This solution works fine but I thought I could do it more elegant :)
> > thanks
>
> > @grigri
> > I'll try this... I don't get it at first glance but I'll try it. It
> > seems like something worth of try...
> > I'll tell you how it went
>
> > P.S. Username "griGri" has something to do with climbing device or
> > not?
>
> > On Nov 19, 12:24 pm, grigri <j...@hendersonwebdesign.com> wrote:
>
> >> Hi Luka
>
> >> This sounds like a job for Set::combine() :
>
> >> <?php
> >> $options = Set::combine(
> >>         $product['ProductVariant'],
> >>         '{n}.id',
> >>         array(
> >>                 '{0} | {1} - {2}',
> >>                 '{n}.sex', '{n}.size', '{n}.price'
> >>         )
> >> );
>
> >> echo $form->select('variant', $options);
> >> ?>
>
> >> hth
> >> grigri
>
> >> On Nov 19, 10:42 am, luigi7up <luigi...@gmail.com> wrote:
>
> >>> Hello I need help with populating drop down select element.
>
> >>> I have following data in array $product that is available in my view
>
> >>> Array
> >>> (
> >>>     [Product] => Array
> >>>         (
> >>>             [id] => 1
> >>>             [product_category_id] => 1
> >>>             [user_id] => 26
> >>>             [title] => Nije Vuk Ovca
> >>>             [folder] => nije_vuk_ovca
> >>>             [price] => 85
> >>>             [special] => 0
> >>>             [published] => 1
> >>>             [created] =>
> >>>             [modified] => 2008-11-07 11:56:06
> >>>         )
>
> >>>     [ProductVariant] => Array
> >>>         (
> >>>             [0] => Array
> >>>                 (
> >>>                     [id] => 1
> >>>                     [product_id] => 1
> >>>                     [sex] => male
> >>>                     [size] => S
> >>>                     [extras] =>
> >>>                     [price] =>
> >>>                 )
>
> >>>             [1] => Array
> >>>                 (
> >>>                     [id] => 2
> >>>                     [product_id] => 1
> >>>                     [sex] => male
> >>>                     [size] => M
> >>>                     [extras] =>
> >>>                     [price] =>
> >>>                 )
>
> >>>             [2] => Array
> >>>                 (
> >>>                     [id] => 3
> >>>                     [product_id] => 1
> >>>                     [sex] => male
> >>>                     [size] => L
> >>>                     [extras] =>
> >>>                     [price] =>
> >>>                 )
>
> >>> )
>
> >>> ****
> >>> As you can see Product has it's variants because PRODUCT model hasMany
> >>> PRODUCT_VARIANTS.
> >>> In my product view I want drop down menu (SELECT) with all variants of
> >>> product to be populated in following way:
>
> Isn't  $this->Product->ProductVariant->find('list') what you're loooking
> for?
>
> I'm using something similar athttp://anunciostotal.net/ads/addto
> populate the subcategories and provinces select boxes.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: