解决yii的CGridView在高级搜索选项过多时点分页后php崩溃的情况
可以将以下代码放到views/layouts/main.php文件的底部,修正CGridView分页链接的地址。
[html]
Yii::app()->clientScript->registerScript('pagerHref', "
$(function(){
$('.pager a').each(function(){
var href = $(this).attr('href');
var page = href.match(/\/([\w]+)_page\/([0-9]+)/);
if (page != null) {
page = page[1]+'_page='+page[2];
} else {
page = '';
}
var sort = href.match(/\/([\w]+)_sort\/([\w]+)/);
if (sort != null) {
sort = sort[1]+'_sort='+sort[2];
} else {
sort = '';
}
var fields = $('.search-form form').serializeArray();
var data = '';
$.each(fields, function(i, field){
if (field.value != '') {
if (data == '') {
data += field.name + '=' + field.value;
} else {
data += '&' + field.name + '=' + field.value;
}
}
});
if (data != '' && page != '') {
page = '&' + page;
}
if ((data != '' || page != '') && sort != '') {
sort = '&' + sort;
}
var url = '".$this->createUrl($this->id.'/'.$this->action->id)."?' + encodeURI(data) + page + sort;
$(this).attr('href', url);
});
});
");
?>
上一篇: CI框架源码阅读---------Model.php
下一篇: php长字符串定义方法_PHP