How to make a dropdown
in yii2
using an activeform
and a model? Since all the methods has changed in yii2
,how it is done in the new one?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
It Seems there are many good answers for this question .So i will try to give a detailed answer
active form and hardcoded data
or
active form and data from a db table
we are going to use ArrayHelper so first add it to the name space by
ArrayHelper has many use full functions which could be used to process arrays map () is the one we are going to use here this function help to make a map ( of key-value pairs) from a multidimensional array or an array of objects.
not part of a active form
or
not an active form but data from a db table
Following can also be done. If you want to append prepend icon. This will be helpful.
This will help you...Don't forget to use the class file in header.
There are some good solutions above, and mine is just a combination of two (I came here looking for a solution).
@Sarvar Nishonboyev's solution is good because it maintains the creation of the form input label and help-block for error messages.
I went with:
Again, full credit to: @Sarvar Nishonboyev's and @ippi
Maybe I'm wrong but I think that SQL query from view is a bad idea
This is my way
In controller
And in View
Or using ActiveForm
It seems you've found your answer already but since you mentioned the active form I'll contribute with one more, even if it differs only ever so slightly.