Page Break Using Doctrine and ZF2

I am trying to implement pagination using ZF2 and Doctrine.

What I'm trying to do here is to extract data from a linked table, you can say "xyz".

Where, as a table of my categories, makes one, many independent links to your PC. MY catgories tables have the following feilds

  • ID (PK)
  • created_at
  • Category_id (PK Self-Regulation)

My XYZ table allows me to say that it is called a name table

  • ID (PK)
  • category_id (FC)
  • name
  • Detail

This is what I am trying to do to retrieve data

public function allSubcategories($id, $column, $order) { $repository = $this->entityManager->getRepository('Category\Entity\Category'); $queryBuilder = $repository->createQueryBuilder('category'); $queryBuilder->distinct(); $queryBuilder->select('category'); $queryBuilder->join('Category\Entity\CategoryName', 'category_name', 'WITH', 'category.id = category_name.category'); $queryBuilder->orderBy("category.status"); $q = $queryBuilder->getDql(); return $query = $this->entityManager->createQuery($q); } 

And in my controller, this is what I do

  public function subcategoryAction() { ///////////////////////////InPut Params Given for the pagination $category_id = (int) $this->params()->fromRoute('id', 0); $page = (int) $this->params()->fromRoute('page', 0); $column = $this->params()->fromQuery('column'); $order = $this->params()->fromQuery('order'); $categoryModel = $this->getServiceLocator()->get('Category'); $categoryModel->category = $category_id; $perPage = 10; $request = $this->getRequest(); if ($request->isGet()) { $view = new ViewModel(); $query = $categoryModel->allSubcategories($category_id, $column, $order); $paginator = new ORMPaginator($query); $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter(array($paginator))); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(2); } return array('id' => $category_id, 'view' => $paginator); } 

Now I am not getting results with the implementation of pagination, can anyone 1 recognize me about what I do not see?

+7
source share
1 answer

You use the wrong page there. Instead, you can use one of the DoctrineORMModule (see DoctrineORMModule\Paginator\Adapter\DoctrinePaginator ).

This may not be very obvious, but the logic is similar to what you already wrote:

 use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator as PaginatorAdapter; use Doctrine\ORM\Tools\Pagination\Paginator as ORMPaginator; use Zend\Paginator\Paginator as ZendPaginator; $query = $categoryModel->allSubcategories($category_id, $column, $order); $paginator = new ZendPaginator(new PaginatorAdapter(new ORMPaginator($query))); 
+7
source

All Articles