usint form_dropdown() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: usint form_dropdown() (/showthread.php?tid=77450) |
usint form_dropdown() - Martin_Salas - 09-02-2020 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 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 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 RE: usint form_dropdown() - InsiteFX - 09-03-2020 Return an object from your model and then pass the object to this helper method. PHP Code: // ----------------------------------------------------------------------- Call it like this. PHP Code: $options = objToAssocArray($yourObject); See if that works for you. RE: usint form_dropdown() - Martin_Salas - 09-03-2020 Thank you very much for your answer, but the function you propose does not result in an associative array of the required form. PHP Code: $options = ['1' => 'asasasa', RE: usint form_dropdown() - InsiteFX - 09-04-2020 If it did not work then your not getting the data from the database as an object. Another way of doing it is to type cast the type: PHP Code: $newTypes = (array)$types; These will only work if you pass it an object array. |