I want to generate a checkbox list which loads all the software names.So for each time a new software is added into the database a checkbox list is created.What are the steps ? Thanks
ArrayHelper::map() will take care of this transformation for you.
Create a model for the input form. Let’s say it’s MyForm. And in the model declare a variable for the software selection. It should be an array of integers.
class MyForm extends Model
{
...
/**
* @var integer[] software selection
*/
public $soft_ids;
...
}
And write a rule for it. You should use each and exist validators.
Note that you should use Html::checkboxList() or Html::activeCheckboxList() instead of ActiveField::checkboxList() when you don’t want to use ActiveForm. But all of these methods take the same parameter of $items that is an array of checkbox items, keys being the input values and the values being the visible labels. That’s why we write Software::getSoftwareList() like that.
Iam trying to render just the checkbox list on its own is it possible ? eg .Software on the navbar,If clicked on it displays only the checkbox list and user can choose accordingly. Iam not creating a user input form where any details are being entered.
Well, it doesn’t make sense to me when you say “just display a checkbox list, without collecting user input”.
When you are collecting some input from the user, then there should be a form, even if you won’t save the result to db. IMO you should consider creating a simple model class extending Model that doesn’t have any relation to db.