Yii implementation check box batch operation of instance code, yii check box instance code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.