I have three const in controller:
const TEST1 = 1;
const TEST2 = 2;
const TEST3 = 3;
How I can call these values in view as a dropDown?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you will get messy with all constants you have in diferent models, you can use code snippet I wrote to manage them. Please see Managing constants easily (yii wiki article)
I will copy just function and one example, but for full wiki and details please go visit link above.
Put this method in parent class or your model class directly:
And after that you can use this method to get specific constants (from one group) in array:
For dropdown it would be looking as (if MyModel have parent ActiveRecord)
Now you can forget to edit all places in code if you adding new constant. It will automaticaly added to all your dropdowns or whatever.