本文整理汇总了PHP中League\Fractal\Resource\Collection::setPaginator方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setPaginator方法的具体用法?PHP Collection::setPaginator怎么用?PHP Collection::setPaginator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Resource\Collection
的用法示例。
在下文中一共展示了Collection::setPaginator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPagedCollection
protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer)
{
$data = $paginator->getCollection();
$collection = new Collection($data, $transformer);
$collection->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->fractal->createData($collection)->toArray();
}
示例2: paginatedCollection
public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
{
$paginator->appends(\Request::query());
$resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->manager->createData($resource)->toArray();
}
示例3: index
public function index()
{
$clinics = Clinic::paginate();
$resource = new Collection($clinics->getCollection(), new ClinicTransformer(), 'clinics');
$resource->setPaginator(new IlluminatePaginatorAdapter($clinics));
return $this->fractal()->createData($resource)->toJson();
}
示例4: index
public function index()
{
$forms = Form::paginate();
$resource = new Collection($forms->getCollection(), new FormTransformer(), 'forms');
$resource->setPaginator(new IlluminatePaginatorAdapter($forms));
return $this->fractal()->createData($resource)->toJson();
}
示例5: createResponseArray
public function createResponseArray($data, $entity, Request $request)
{
$this->request = $request;
$fractal = new Manager();
$fractal->parseIncludes($request->query->get('include', []));
$fractal->setSerializer(new ArraySerializer());
$transformer = $this->transformerFactory->get($entity);
if ($data instanceof Pagerfanta) {
$pager = $data;
$pager->setMaxPerPage($request->query->get('limit', 10));
$pager->setCurrentPage($request->query->get('page', 1));
$results = $pager->getCurrentPageResults();
$resource = new Collection($results, $transformer);
$resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
} elseif ($data instanceof DoctrineQuery) {
$ormAdapter = new DoctrineORMAdapter($data);
$pager = new Pagerfanta($ormAdapter);
$pager->setMaxPerPage($request->query->get('limit', 10));
$pager->setCurrentPage($request->query->get('page', 1));
$results = $pager->getCurrentPageResults();
$resource = new Collection($results, $transformer);
$resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
} elseif (is_array($data)) {
$resource = new Collection($data, $transformer);
} else {
$resource = new Item($data, $transformer);
}
$data = $fractal->createData($resource)->toArray();
return $data;
}
示例6: paginateCollection
private function paginateCollection(Collection $collection, IlluminatePaginator $paginator, PaginatorInterface $adapter = null)
{
if (is_null($adapter)) {
$adapter = new IlluminatePaginatorAdapter($paginator);
}
$collection->setPaginator($adapter);
}
示例7: respondWithPaginatedCollection
public function respondWithPaginatedCollection(AbstractPaginator $paginator, $callback)
{
$resource = new Collection($paginator->getCollection(), $callback);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
$rootScope = $this->fractal->createData($resource);
return $rootScope;
}
示例8: index
public function index()
{
$users = User::paginate();
$resource = new Collection($users->getCollection(), new UserTransformer(), 'users');
$resource->setPaginator(new IlluminatePaginatorAdapter($users));
return $this->fractal()->createData($resource)->toJson();
}
示例9: actionGetElements
/**
* Returns the requested elements as JSON
*
* @param callable|null $configFactory A function for generating the config
* @param array|null $config The API endpoint configuration
*
* @throws Exception
* @throws HttpException
*/
public function actionGetElements($configFactory = null, array $config = null)
{
if ($configFactory !== null) {
$params = craft()->urlManager->getRouteParams();
$variables = isset($params['variables']) ? $params['variables'] : null;
$config = $this->_callWithParams($configFactory, $variables);
}
// Merge in default config options
$config = array_merge(['paginate' => true, 'pageParam' => 'page', 'elementsPerPage' => 100, 'first' => false, 'transformer' => 'Craft\\ElementApi_ElementTransformer'], craft()->config->get('defaults', 'elementapi'), $config);
if ($config['pageParam'] == 'p') {
throw new Exception('The pageParam setting cannot be set to "p" because that’s the parameter Craft uses to check the requested path.');
}
if (!isset($config['elementType'])) {
throw new Exception('Element API configs must specify the elementType.');
}
/** @var ElementCriteriaModel $criteria */
$criteria = craft()->elements->getCriteria($config['elementType'], ['limit' => null]);
if (!empty($config['criteria'])) {
$criteria->setAttributes($config['criteria']);
}
// Load Fractal
$pluginPath = craft()->path->getPluginsPath() . 'elementapi/';
require $pluginPath . 'vendor/autoload.php';
$fractal = new Manager();
$fractal->setSerializer(new ArraySerializer());
// Define the transformer
if (is_callable($config['transformer']) || $config['transformer'] instanceof TransformerAbstract) {
$transformer = $config['transformer'];
} else {
Craft::import('plugins.elementapi.ElementApi_ElementTransformer');
$transformer = Craft::createComponent($config['transformer']);
}
if ($config['first']) {
$element = $criteria->first();
if (!$element) {
throw new HttpException(404);
}
$resource = new Item($element, $transformer);
} else {
if ($config['paginate']) {
// Create the paginator
require $pluginPath . 'ElementApi_PaginatorAdapter.php';
$paginator = new ElementApi_PaginatorAdapter($config['elementsPerPage'], $criteria->total(), $config['pageParam']);
// Fetch this page's elements
$criteria->offset = $config['elementsPerPage'] * ($paginator->getCurrentPage() - 1);
$criteria->limit = $config['elementsPerPage'];
$elements = $criteria->find();
$paginator->setCount(count($elements));
$resource = new Collection($elements, $transformer);
$resource->setPaginator($paginator);
} else {
$resource = new Collection($criteria, $transformer);
}
}
JsonHelper::sendJsonHeaders();
echo $fractal->createData($resource)->toJson();
// End the request
craft()->end();
}
示例10: paginate
/**
* @return mixed
*/
public function paginate()
{
$paginator = $this->repository->paginate();
$bloco = $paginator->getCollection();
$resource = new Collection($bloco, new CategoriaTecidoTransformer());
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $paginator;
}
示例11: respondWithPaginate
protected function respondWithPaginate($paginator, $callback)
{
$collection = $paginator->getCollection();
$resource = new Collection($collection, $callback);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
$rootScope = $this->fractal->createData($resource);
return $this->respondWithArray($rootScope->toArray());
}
示例12: index
public function index(Manager $fractal, TransactionTransformer $transactionTransformer)
{
$transactions = Transaction::orderBy('time', 'desc')->paginate(10);
$collection = new Collection($transactions, $transactionTransformer);
$collection->setPaginator(new IlluminatePaginatorAdapter($transactions));
$data = $fractal->createData($collection)->toArray();
return $this->respond($data);
}
示例13: respondWithPaginator
/**
* @param Paginator $data
* @param TransformerAbstract $transformer
* @param array $headers
* @return \Illuminate\Http\JsonResponse
*/
public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = [])
{
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$resource = new Collection($data->getCollection(), $transformer);
$resource->setPaginator(new IlluminatePaginatorAdapter($data));
$response = $manager->createData($resource)->toArray();
return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers);
}
示例14: transformList
/**
* @param $key
* @param array $resources
* @param PaginatorInterface $paginator
* @param null|string|array $includes
* @return array
*/
public function transformList($key, $resources, $includes = null, PaginatorInterface $paginator = null)
{
$transformer = $this->getTransformer($key);
$resource = new Collection($resources, $transformer);
if ($paginator !== null) {
$resource->setPaginator($paginator);
}
return $this->convertResource($resource, $includes);
}
示例15: createPaginated
/**
* create fractal's collection
*
* @param Collection $collection
* @param TransformerAbstract $transformer
*/
public function createPaginated($paginator, $transformer, $include = [])
{
$fractal = app(League\Fractal\Manager::class);
$fractal->parseIncludes($include);
$collection = $paginator->getCollection();
$resource = new Collection($collection, $transformer);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $fractal->createData($resource);
}