Many people find it hard to make the Yii checkBoxList selected on update view, but believe me in fact its very easy and straight forward. This post will help you in showing user’s last selection by showing them a preselected checkbox list. Need help? You can Email me or Skype chat I Suppose you have created a MANY_MANY relation as given below. Book Model: Author Model: Note: authorbook is the table name containing ids checkBoxList function is taking three parameters. 2nd parameter is important here, because it makes the checkBoxList selected.
'authors' => array(self::MANY_MANY, 'Author', 'authorbook(book_id,author_id)'), 'books' => array(self::MANY_MANY, 'Book', 'authorbook(author_id, book_id)'), Make a selected checkBoxList
$books = CHtml::listData(Book::model()->findAll(), 'id', 'name'); $selected_keys = array_keys(CHtml::listData( $model->books, 'id' , 'id')); echo CHtml::checkBoxList('Author[books][]', $selected_keys, $books);
Yii
How to make Yii checkBoxList selected
Many people find it hard to make the Yii checkBoxList selected on update view, but believe me in fact its very easy and straight forward. This post will help yo
· 5 min read
Related posts
Yii
How to separate front and admin panel in yii-framework
In my previous post I demonstrated you how to render different layout for different user role, now lets move a step forward and see how to create separate front
Yii
How to save multiple related models in Yii [Complete Solution]
Scenario: You are in a situation where you have two related tables a Parent and a child table. You need to create a user experience in which user presses Save b
Yii
Yii 1.1: Behaviors & Events
Behaviors & Events provide endless possibilities and unbelievable flexibility, but as current Yii documentation does not give more than a few examples, it m