Zend + Doctrine. Table
-
I'm a newcomer, Zend is weak. Help me figure out how to set the ZendFramework2 table using Doctrine. Found tutorial- http://bigemployee.com/zend-framework-2-pagination-sorting-tutorial/ I don't know what to do with the doctrine. According to the instructions, the following code should be placed in the object of the table:
use Zend\Db\Sql\Select; ... public function fetchAll(Select $select = null) { if (null === $select) $select = new Select(); $select->from($this->table); $resultSet = $this->selectWith($select); $resultSet->buffer(); return $resultSet; } ...
But Doctrine does not have the properties of $this-statetable.
And the counteraller should indicate the method fetchAll() which is not in essence:
return new ViewModel(array( 'albums' => $this->getAlbumTable()->fetchAll($select), 'order_by' => $order_by, 'order' => $order, ));
Example of my that needs to be sorted across all the table columns except id:
namespace Admin\Entity; use Doctrine\ORM\Mapping as ORM;
class Customer
{
private $id;
private $login;
private $password;
private $email;
private $category;public function getId()
{
return $this->id;
}
public function setLogin($login)
{
$this->login = $login;return $this;
}
public function getLogin()
{
return $this->login;
}
public function setPassword($password)
{
$this->password = $password;return $this;
}
public function getPassword()
{
return $this->password;
}
public function setEmail($email)
{
$this->email = $email;return $this;
}
public function getEmail()
{
return $this->email;
}
public function setCategory(\Admin\Entity\Category $category = null)
{
$this->category = $category;return $this;
}
public function getCategory()
{
return $this->category;
}
}
My IndexAction in the controller is as follows:
$query = $this->getEntityManager()->createQueryBuilder();
$query
->select('u')
->from('Admin\Entity\Customer', 'u')
->orderBy('u.id', 'DESC');$adapter = new DoctrineAdapter(new ORMPaginator($query)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(3); $paginator->setCurrentPageNumber((int) $this->params()->fromQuery('page', 1)); return array('customers' => $paginator);
How to sort a table of the essence of the doctrine in that case? The doctrine has no way of sorting the table.
-
In this controller, it is possible to sort the nature of the request.
Change
->orderBy('u.id', 'DESC');
♪
->orderBy('u.'.$order_by, $order);
And everything else will be like the Tutorial.