dcat-admin icon indicating copy to clipboard operation
dcat-admin copied to clipboard

用repository-get方法导出时报错

Open rainhon opened this issue 3 years ago • 2 comments

  • Laravel Version: 8.54.0
  • PHP Version: 7.4
  • Dcat Admin Version: 2.1.5-beta

Description:

创建的repository get分页导出的时候会出现报错 --由于返回的makePaginator方法内无法获取到perPage和currentPage,导致除零错误;

Steps To Reproduce:

1、创建新的repository 2、实现get方法,返回$model->makePaginator($total, $data) 3、导出分页或者全部导出,报错

rainhon avatar Apr 12 '22 03:04 rainhon

我自己找到解决方法是在get方法最前面添加 $model->usePaginate();

希望能在文档里说明或者自动补全这个方法引用,避免别人遇到同样的问题。

rainhon avatar Apr 12 '22 03:04 rainhon

我不使用分页,导出会一直循环执行,直接504了

williamqian avatar Aug 25 '22 05:08 williamqian

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 21 '23 18:02 stale[bot]

$model->usePaginate(); 没有解决我的问题。

我的是get完全自定义数据, 分页的时候使用 return $model->makePaginator($total, $data); 导出数据的时候使用 return $data; 这时候get会无限循环下去。 使用
if($is_export){ foreach ($model->getQueries() as $q){ if($q['method']=='forPage'){ list($currentPage,$perPage)=$q['arguments']; } } } 获取当前系统给model用的当前页currentPage和每页行数perPage,重新使用到自己的查询上去,

理论是让自己的data在没数据的时候返回空数组就行了 这是我的解决方法,希望可以帮到你

liucodeing avatar Jun 19 '23 10:06 liucodeing