I have a simple activeradiobuttonlist that is not showing any checked/unchecked values in the form on either initial page entry or a post back.
<div class="row">
<?php echo CHtml::activeRadiobuttonlist($model,'comment_option', array('enable_commenting_by_everyone'=>'Allow everyone to comment.', 'enable_commenting_by_friends_only'=>'Allow only friends to comment.', 'disable_commenting'=>'Allow no one to comment.')); ?>
</div>
enable_commenting_by_everyone,enable_commenting_by_friends_only and disable_commenting are database columns in the model.
Not sure what I am missing. Seems like it should just work.
to debug easily you can check the info in $_POST when you submit… you can do it easily with firebug if you’re using firefox or it’s integrated to chrome.
EDIT:
why not rather use, if you are in your form, $form->radioButtonList($model…); instead
This is fine. I can easily add logic to update the different database columns but the model isn’t populating the radio buttons on initial page entry or on save. And, I can’t find any documentation that aids in setting up the parameters other than the way it currently is.
It is just me or is YII just poorly documented? I can’t find an example that fits my use case.
Why don’t I use $form->, what is the advantage of that? Maybe I should read up on it but frankly I’m very busy and simply need straightforward solutions instead of having to spend way more time futzing with very trivial stuff.
This passes the individual radio button values. The model does populate the radio buttons on initial page entry or on save as one would expect. But once I group the radio buttons, I lose that. I’m working on that example. Seems that the framework would be able to handle it. I’m not sure what I am missing here.
Unfortunately, I have to continue working on other examples until I find a reasonable solution. I’ll post anything I find that may be useful. Can someone point me to a relevant example?
Another attempt. Now the grouping of the radio buttons removes the radio button values from the Account model. So, the radio buttons on the page are never set.
I have an account settings page. On that page I have some checkboxes and then the three radio buttons.
Account settings page:4656
The checkboxes work fine. See below. They are populated with the correct values that are in the database. Each checkbox is mapped to a single database column. Each radio button is also mapped to a database column. The database columns for the radio are as follows:
enable_commenting_by_everyone
enable_commenting_by_friends_only
disable_commenting
I’ve not been unable to have success in doing the same for the radio buttons. See my previous posts. Since the radio buttons are a group, I only want one to be selected at a time and also want to have the one selected to be checked on initial page entry and any postback. That’s it. Very simple. Seems not so simple in YII.
I have mixed emotions about YII. I’m at fault to a degree because I haven’t read every piece of documentation but then do I really need to do that. I am a fairly experienced web app developer. Give me an example and I can get it to work. I’m not finding relevant examples in YII documentation. Yeah, the class definitions are there but not relevant examples. This isn’t the first time I’ve run into this. I chose YII without a lot of testing but YII looks strong on the surface until you get into certain use cases they you have to spend an inordinate amount of time figuring out how to do some of the simplest things, like populating radio buttons from a database.
It is easy to get the selected value from the radiobuttonlist on post. The problem I’m having has to do with getting the values from the database mapped back to each radiobutton in the list. I simply don’t see how this is done using the activeRadiobuttonlist.
I can see now, after a ton of frustration, that my database model won’t work with the activeRadiobuttonlist. What I need to do is to have a single column in the database that will hold an integer that will map to each of the different commenting options. Then I’ll need to create an enum and use it appropriately with queries or whatever.
<div class="row">
<?php echo CHtml::activeRadiobuttonlist($model, 'tok_commenting_option', array('1'=>'Allow everyone to comment.', '2'=>'Allow only friends to comment.', '3'=>'Allow no one to comment.'),array('class'=>'commenting_opts')); ?>
</div>
tok_commenting_option is a property of the model and also a column in the database.
Spent way too much time on this one. Oh well…live and learn.