Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can I use a collection of models as the option array argument for Form::select()?
I'm creating a form where a select box is populated with model data, e.g. I have a book model it belongs to a category model. In the from I use to create a book, I want the list of categories to show up on the form as a select box, how do I do that without iterating through the collection categories to build the options array manually?
No, you can not. Select options requires key-value pairs, which is not available in a model.
If a model would provide that functionality somewhere (I wouldn't know how btw), it would be the select() method that would have to iterate over the collection. So iterate you have to.
We use a standard dropdown() method in our base model which does a DB query to return a key-value list, it has recently be discussed here:
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion