usint form_dropdown() |
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
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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',
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |