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);
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
Related posts
Yii
Remove index.php from URL in YII
Learn how to configure Yii's UrlManager and Apache .htaccess rules to create clean, user-friendly URLs. This guide covers URL configuration, rewrite rules, common issues, and practical tips for improving Yii application routing
Yii
Yii Rights: Get all assigned roles of a user
Learn how to retrieve user roles in Yii Framework using the authassignment table, CDbCommand, and queryAll(). This guide explains how to fetch and store user roles, use parameter binding for safer SQL queries, leverage Yii’s built-in authorization manager, and implement role-based access control in PHP applications.
Yii
Disabled Yii logs and stack trace messages
Open up the index.php from root folder and comment out following 2 lines [code language=”php”] defined(‘YII_DEBUG’) or define(‘YII