倒導php崩潰是因為選項過多,其實為空的選項可以不用添加到分頁的url上。 可以將以下代碼放到views/layouts/main.php文件的底部,修正CGridView分頁鏈接的地址。 [html] <?php 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); }); }); "); ?>