Yii implementation check box batch operation of instance code, yii check box instance code
Sort out the document, search for a Yii implementation check box to operate the instance code in batches, and streamline the code for sharing.
In the View
<? Php $ this-> widget ('zii. widgets. grid. CGridView ', array ('id' => 'user-grid', 'dataprovider' => $ model-> search (), // a search () is required in the Model () method, $ model is the Model object passed in the Controller // 'filter' => $ model, 'columns '=> array ('selectablerdones' => 2, 'class' => 'ccheckboxcolumn', 'headerhtmloptions '=> array ('width' => '18px', 'align '=> 'center '), 'checkboxhtmloptions '=> array ('name' => 'IDs []', 'align '=> 'center'),), 'homewo Rk_numberID ', 'type', 'target', 'state', 'author _ id', array ('name' => 'state ', 'type' => 'Raw', 'value' => '($ data-> state = "not_read "? "Unread": "reviewed") '), // array ('name' => 'passrecord', 'type' => 'date '), array ('name' => 'submit _ time', 'type' => 'date '), array ('class' => 'cbuttoncolumn',);?>
<Select name = "status" id = "status"> <option value = "1"> pass </option> <option value = "0"> fail </option> </select> <button type = "button" onclick = "setStatus (); "style =" width: 120px; "> set status </button> <script type =" text/javascript "> function getData () {var data = new Array (); $ ("input: checkbox [name = 'IDs [] ']"). each (function () {if ($ (this ). attr ("checked") {data. push ($ (this ). val () ;}}); return data;} function setStat Us () {var data = getData (); if (data. length <1) {alert ('select at least one project. '); Return;} // here is the url post method passed $. post ("index. php? R = user/status ", {'IDs [] ': data, 'status': $ (' # status '). val ()}, function (data) {if (data = 'OK') {alert ('status set successfully! ');} Else {alert (' setting status failed. Please try again! ');} Window. open ('index. php? R = user/admin ', 'mainframework') ;;}</script>
Search () function in Model
Public function search () {// @ todo Please modify the following code to remove attributes that shocould not be searched. $ criteria = new CDbCriteria; // $ criteria-> with = array ('author '); // added eager loading with author // $ this-> state = "not_passed"; $ criteria-> compare ('state', $ this-> state ); // here, a compare is added. username is the field of the User table, and $ this-> name is the attribute we added, true: Fuzzy search // $ criteria-> compare ('username', $ this-> name, true); return new CActiveDataProvider ($ this, array ('Criteria '=> $ criteria ,));
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.