List Info

Thread: Re: filling an array for a selectbox (v1.2)




Re: filling an array for a selectbox (v1.2)
user name
2008-02-23 17:52:11
On Sat, Feb 23, 2008 at 2:59 PM, Ronald <ronaldvexs4all.nl> wrote:
>
>  It's probably something simple, but I'm trying to
figure this out for
>  a few hours now and I just can't get it right.
>
>  I'm building a component and one function needs to
return an array I
>  can use to fill a selectbox.
>  This return array needs to be filled from an array of
objects,.
>
>  This is my loop to walk trough the array of objects.
>  ---
>  for($i = 0; $i < count($issuerArray); $i++)
>  {
>         //$issuerArray[$i]->issuerID           <-
this needs to be the id of
>  every option
>         //$issuerArray[$i]->issuerName;     <-
this needs to be the value of
>  every option
>  }
>  ---
>  My question is how to get these values into a array
(the return array)
>  in such a way that I can use it to fill an selectbox.
>  I tried several things but I allways end up with a
selectbox with all
>  kind of strange values in it.
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Cake PHP" group.
To post to this group, send email to cake-phpgooglegroups.com
To unsubscribe from this group, send email to
cake-php-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: filling an array for a selectbox (v1.2)
user name
2008-02-23 17:57:51
Anyway ...

Say you have a table, 'regions', with columns 'id' &
'name':

$this->set('regions',
$this->Region->find('list'));

Or, if this is an associated model:

$this->set('regions',
$this->Country->Region->find('list'));

View:

<?= $form->select('Country.region', $regions, null,
array(), true) ?>

Use different column name:

$this->Country->Region->displayField = 'name_en';
$this->set('regions',
$this->Country->Region->find('list'));

On Sat, Feb 23, 2008 at 6:52 PM, b logica <foo.logicagmail.com> wrote:
>
> On Sat, Feb 23, 2008 at 2:59 PM, Ronald
<ronaldvexs4all.nl> wrote:
>  >
>  >  It's probably something simple, but I'm trying
to figure this out for
>  >  a few hours now and I just can't get it right.
>  >
>  >  I'm building a component and one function needs
to return an array I
>  >  can use to fill a selectbox.
>  >  This return array needs to be filled from an
array of objects,.
>  >
>  >  This is my loop to walk trough the array of
objects.
>  >  ---
>  >  for($i = 0; $i < count($issuerArray); $i++)
>  >  {
>  >         //$issuerArray[$i]->issuerID          
<- this needs to be the id of
>  >  every option
>  >         //$issuerArray[$i]->issuerName;    
<- this needs to be the value of
>  >  every option
>  >  }
>  >  ---
>  >  My question is how to get these values into a
array (the return array)
>  >  in such a way that I can use it to fill an
selectbox.
>  >  I tried several things but I allways end up with
a selectbox with all
>  >  kind of strange values in it.
>  >
>  >  >  >
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Cake PHP" group.
To post to this group, send email to cake-phpgooglegroups.com
To unsubscribe from this group, send email to
cake-php-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )