Welcome Guest, Not a member yet? Register   Sign In
usint form_dropdown()
#1

(This post was last modified: 09-02-2020, 10:31 PM by Martin_Salas.)

Hello, the table "types" is formed in the following way:

id     |       name   |      description
1      |       one      |       none
2      |       two       |      none
3      |       three    |       NULL
this table is used to fill options in a <select> tag to do this I can use:

 
Code:
echo form_dropdown ('Types',$options);


However $options is an associative array and I can't do the following in a controller:

Code:
// in a controller
$types = new Types ();
$options = $types->findAll();
// in a view
echo form_dropdown ('Types', $options);

what I think I need is a method similar to findAll () but that returns an associative array to avoid what I currently do which is:

Code:
// in a controller
$ types = new Types ();
$ options = [];
foreach ($types->findAll() as $type) {
  $ options = $options + [$type['id'] => $type['name']];
}
// in a view
echo form_dropdown ('Types', $options);


My question is:
Is there a simple way to populate the $options array avoiding doing what I do?
Thank you very much for reading me and your help
Reply


Messages In This Thread
usint form_dropdown() - by Martin_Salas - 09-02-2020, 10:24 PM
RE: usint form_dropdown() - by InsiteFX - 09-03-2020, 04:02 AM
RE: usint form_dropdown() - by Martin_Salas - 09-03-2020, 06:37 PM
RE: usint form_dropdown() - by InsiteFX - 09-04-2020, 12:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB