You are here

Drupal 8 Pager 链接问题解决

  作者: 老葛 亚艾元软件

网站的pager url,是这个样子的:

http://chess.yaiyuan.com/qipus?q=qipus&page=1

http://chess.yaiyuan.com/qipus?q=qipus&page=2

想把它改为:

http://chess.yaiyuan.com/qipus?page=2


多了一个q,


同样的代码,放到本地测试,没有问题。但是在线就存在这个问题,虽然不影响功能,但是一致没有弄明白怎么回事。


多次确认,检查,原来是nginx的问题,在线采用的nginx,本地采用的apache。


最后这样解决:


function pager_get_query_parameters() {

  $query = &drupal_static(__FUNCTION__);

  if (!isset($query)) {

    $query = UrlHelper::filterQueryParameters(\Drupal::request()->query->all(), ['page', 'q']);

  }

  return $query;

}

将q从中排除掉。

不过这个是直接修改的源代码,更好的办法,是不改核心代码,就能搞定。




exclude $_GET['q'] parameter from pager url for Drupal 8 on nginx


in one Drupal 8 site on nginx, I get following pager urls:

http://chess.yaiyuan.com/qipus?q=qipus&page=1

http://chess.yaiyuan.com/qipus?q=qipus&page=2

...

my expectation is :

http://chess.yaiyuan.com/qipus?page=1

http://chess.yaiyuan.com/qipus?page=2


For apache, it works as my expectation, but for nginx, it is a little strange.


I fix it by hack the core code:

function pager_get_query_parameters() {

  $query = &drupal_static(__FUNCTION__);

  if (!isset($query)) {

    $query = UrlHelper::filterQueryParameters(\Drupal::request()->query->all(), ['page', 'q']);

  }

  return $query;

}


Is there a way that I could hook/plug into it that allow write some code in my custom module to fix this issue? 


论坛:

Drupal版本: