我有代码
$qb = $this->createQueryBuilder('country');
$adapter = new DoctrineORMAdapter($qb);
$this->pagerfanta = new Pagerfanta($adapter);
$this->pagerfanta->setMaxPerPage(10);
$this->pagerfanta->setCurrentPage(1);
var_dump($this->pagerfanta->getNbResults());
var_dump($this->pagerfanta->getCurrentPageResults());
结果
int(242)
object(ArrayIterator)#12190 (1) {["storage":"ArrayIterator":private]=> array(0) { } }
但是我在dev.log中看到以下几行
[2018-10-09 17:37:43] doctrine.DEBUG: SELECT DISTINCT id_0 FROM (SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_) dctrn_result LIMIT 10 [] []
[2018-10-09 17:37:43] doctrine.DEBUG: SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_ WHERE c0_.id IN (?) [["[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0042840f-843e-457d-9250-b1e22d8d6d5e)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 01c4f446-48a9-413f-9225-7138c0e39f98)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 029bed5c-35f2-4c7d-812c-7d7d3d886be1)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 02c0460d-8902-4cf7-a070-e6404f321c25)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0315d760-5dea-412e-8242-7eceb7373375)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 033d07bb-c4ce-4166-991b-a5441bcf2b7e)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 035ce32a-3b21-40e8-ae58-ee3a15fd6c71)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 054f444e-c8d2-48ad-a058-5bd94ff8a133)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 05bafdf7-a31e-4d84-8db7-a03f3bb0d670)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0873c562-db8a-4189-af35-82d5d80b7fe9)"]] []
[2018-10-09 17:37:43] doctrine.DEBUG: SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_) dctrn_result) dctrn_table [] []
所以看起来有些事情发生了。至少我得到正确的NB计数。但是空的getCurrentPageResults。可能是我的ID是基于CountryID UUID的问题?