yii gii自动生成的curd增多批量删除实例

2020-02-08 13:36栏目:编程
TAG:

本文实例讲述了Yii中CGridView实现批量删除的方法。分享给大家供大家参考,具体如下:

1.在视图中 CGridView中的columns添加,作用是添加多选框

本文中,收集了一些比较常用的Javascript函数,希望对学习JS的朋友们有所帮助。1. 字符串长度截取

  1. CGridView中的columns添加

    array( 'selectableRows' => 2, 'footer' => '批量删除', 'class' => 'CCheckBoxColumn', 'headerHtmlOptions' => array, 'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),),

    /<![CDATA[/var GetCheckbox = function (){ var data=new Array(); $("input:checkbox[name='selectdel[]']").each{ if.attr{ data.push; if{ $.post('<&#63;php echo CHtml::normalizeUrl(array('/admin/words/delall/'));&#63;>',{'selectdel[]':data}, function { var ret = $.parseJSON; if (ret != null && ret.success != null && ret.success) { $.fn.yiiGridView.update; }else{ alert; }}/]]>/

    public function actionDelall->request->isPostRequest) { $criteria= new CDbCriteria; $criteria->addInCondition('id', $_POST['selectdel']); Words::model()->deleteAll;//Words换成你的模型 if->request->isAjaxRequest)) { echo CJSON::encode(array; } else { $this->redirect(isset ? $_POST['returnUrl'] : array; } } else throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');}

 代码如下

function cutstr { var temp, icount = 0, patrn = /[^x00-xff]/, strre = ""; for (var i = 0; i < str.length; i++) { if  { temp = str.substr; if  == null) { icount = icount + 1 } else { icount = icount + 2 } strre += temp } else { break; } } return strre + "..."}

String.prototype.replaceAll = function { return this.replace, s2)}

String.prototype.trim = function() { var reExtraSpace = /^s*s+$/; return this.replace}

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

array(
       'selectableRows' => 2,
       'footer' => '<button type="button" onclick="GetCheckbox();" style="width:76px">批量删除</button>',
       'class' => 'CCheckBoxColumn',
       'headerHtmlOptions' => array('width' => '33px'),
       'checkBoxHtmlOptions' => array('name' => 'selectdel[]'),
     ),

  1. 清除左空格/右空格

    function ltrim{ return s.replace; } function rtrim{ return s.replace; }

  2. 判断是否以某个字符串开头

    String.prototype.startWith = function { return this.indexOf == 0}

  3. 判断是否以某个字符串结束

    String.prototype.endWith = function { var d = this.length - s.length; return (d >= 0 && this.lastIndexOf}

  4. 转义html标签

    function HtmlEncode { return text.replace.replace.replace.replace}

  5. 时间日期格式转换

    Date.prototype.Format = function { var str = formatStr; var Week = ['日', '一', '二', '三', '四', '五', '六']; str = str.replace(/yyyy|YYYY/, this.getFullYear; str = str.replace(/yy|YY/, > 9 ? .toString() : '0' + ); str = str.replace(/MM/, > 9 ? .toString() : '0' + ; str = str.replace(/M/g, ; str = str.replace(/w|W/g, Week[this.getDay; str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate : '0' + this.getDate; str = str.replace(/d|D/g, this.getDate; str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours : '0' + this.getHours; str = str.replace(/h|H/g, this.getHours; str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes : '0' + this.getMinutes; str = str.replace(/m/g, this.getMinutes; str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds : '0' + this.getSeconds; str = str.replace(/s|S/g, this.getSeconds; return str}

  6. 判断是否为数字类型

    function isDigit { var patrn = /^[0-9]*$/; if == null || value == "") { return false } else { return true }}

  7. 设置cookie值

    function setCookie { var d = new Date(); var offset = 8; var utc = d.getTime() + 60000); var nd = utc + ; var exp = new Date; exp.setTime + Hours 60 60 1000); document.cookie = name + "=" + escape + ";path=/;expires=" + exp.toGMTString() + ";domain=360doc.com;"}

  8. 获取cookie值

    function getCookie { var arr = document.cookie.match" + name + "=; if return unescape; return null}

    function AddFavorite { try { window.external.addFavorite } catch { try { window.sidebar.addPanel } catch { alert("加入收藏失败,请使用Ctrl+D进行添加") } }}

    function setHomepage { document.body.style.behavior = 'url'; document.body.setHomePage } else if { if { try { netscape.security.PrivilegeManager.enablePrivilege } catch { alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true") } } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', '') }}

    function LoadStyle { try { document.createStyleSheet { var cssLink = document.createElement; cssLink.rel = 'stylesheet'; cssLink.type = 'text/css'; cssLink.href = url; var head = document.getElementsByTagName[0]; head.appendChild }}

    function evalscript { if == -1) return s; var p = /]&#63;></script>/ig; var arr = []; while { var p1 = /<script[^>]&#63;src=""[^>]&#63;&#63;(&#63;:charset="&#63;></script>/i; var arr1 = []; arr1 = p1.exec { appendscript(arr1[1], '', arr1[2], arr1[3]); } else { p1 = /<script></script>/i; arr1 = p1.exec; appendscript('', arr1[2], arr1[1].indexOf; } } return s;}</pre><pre >function stripscript { return s.replace(/<script.&#63;>.*&#63;</script>/ig, '');}</pre><p>17. 动态加载脚本文件</p><pre >function appendscript(src, text, reload, charset) { var id = hash; if(!reload && in_array return; if { $.parentNode.removeChild; } evalscripts.push; var scriptNode = document.createElement; scriptNode.type = "text/javascript"; scriptNode.id = id; scriptNode.charset = charset &#63; charset : (BROWSER.firefox &#63; document.characterSet : document.charset); try { if { scriptNode.src = src; scriptNode.onloadDone = false; scriptNode.onload = function () { scriptNode.onloadDone = true; JSLOADED[src] = 1; }; scriptNode.onreadystatechange = function () { if((scriptNode.readyState == 'loaded' || scriptNode.readyState == 'complete') && !scriptNode.onloadDone) { scriptNode.onloadDone = true; JSLOADED[src] = 1; } }; } else if{ scriptNode.text = text; } document.getElementsByTagName[0].appendChild; } catch {}}</pre><p>18. 返回按ID检索的元素对象</p><pre >function $ { return !id &#63; null : document.getElementById;}</pre><p>19. 跨浏览器绑定事件</p><pre >function addEventSamp{ if{return;} if { obj.addEventListener; }else if{ obj.attachEvent; }else{ oTarget["on" + sEvtType] = fn; } }</pre><p>20. 跨浏览器删除事件</p><pre >function delEvt{return;} if{ obj.addEventListener; }else if{ obj.attachEvent; }else{ obj["on" + evt] = fn; }}</pre><p>21. 为元素添加on方法</p><pre >Element.prototype.on = Element.prototype.addEventListener; NodeList.prototype.on = function {、 []['forEach'].call { el.on; return this;};</pre><p>以上就是本文的全部内容,喜欢的就收藏吧!</p>

2.引入js代码

版权声明:本文由bob体育app发布于编程,转载请注明出处:yii gii自动生成的curd增多批量删除实例