PHP code example of arturdoruch / paginator-bundle

1. Go to this page and download the library: Download arturdoruch/paginator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arturdoruch / paginator-bundle example snippets


// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new ArturDoruch\PaginatorBundle\ArturDoruchPaginatorBundle(),
    );
}

$paginator = $this->get('arturdoruch_paginator');

$paginator->paginate($query, $page, $limit);

// AppBundle\Controller\ProjectController.php

public function listAction($page, Request $request)
{
    $repository = $this->getDoctrine()->getRepository('AcmeProjectBundle:Project');
    $paginator = $this->get('arturdoruch_paginator');
    
    // Doctrine\ORM\QueryBuilder
    $qb = $repository->createQueryBuilder('p')
        ->select('p');
    
    $projects = $paginator->paginate($qb, $page, 5);

    // Doctrine\ORM\Query
    $query = $repository->createQueryBuilder('p')
        ->select('p')
        ->getQuery();

    $projects = $paginator->paginate($query, $page, 5);    

    return $this->render('AppBundle:Project:list.html.twig', array(
        'projects' => $projects
    ));
}

// todo

// todo

// AppBundle\Controller\ProjectController.php

public function listAction($page, Request $request)
{
    $projectsList = array(
            array(
                'id' => 1,
                'name' => 'PHP'
            ),
            array(
                'id' => 2,
                'name' => 'JS'
            ),
            array(
                'id' => 3,
                'name' => 'Symfony'
            ),
            array(
                'id' => 4,
                'name' => 'Github'
            ),
            array(
                'id' => 5,
                'name' => 'SCSS'
            )
            ...
        );

    $paginator = $this->get('arturdoruch_paginator');
    $projects = $paginator->paginate($projectsList, $page, 5);

    return $this->render('AppBundle:Project:list.html.twig', array(
        'projects' => $projects
    ));
}