Skip to content

Instantly share code, notes, and snippets.

@weierophinney
Created June 5, 2018 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weierophinney/4425a8542186310673613e7c5ed16226 to your computer and use it in GitHub Desktop.
Save weierophinney/4425a8542186310673613e7c5ed16226 to your computer and use it in GitHub Desktop.
Example of casting an array of entities to a collection
<?php
namespace App\Entity;
use ArrayIterator;
class UserCollection extends ArrayIterator
{
}
<?php
$users = new UserCollection($userRepository->findAll());
@weierophinney
Copy link
Author

Note the change from extending Zend\Paginator\Paginator to extending ArrayIterator.

If you want to do pagination, you'll need to use something like the https://github.com/doctrine/DoctrineORMModule/blob/master/src/DoctrineORMModule/Paginator/Adapter/DoctrinePaginator.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment