IndexController
public function indexAction()
{
$sm =
$this->getServiceLocator()->get('application_settings_service')->getSettings();
$select = $this->getArticlesTable()->getArticlesSelect($sm['site_id']);
$paginator = new \Zend\Paginator\Paginator(new
\Zend\Paginator\Adapter\DbSelect($select,
$this->getArticlesTable()->getAdapter()));
$paginator->setItemCountPerPage(3);
$paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
return array(
'articles' => $paginator,
);
}
Model
public function getArticlesSelect($site=1)
{
$commentsCount = new Select();
$commentsCount
->from('articles_comments')
->columns(array('count' => new
Expression('COUNT(articles_comments.id)')))
->where($this->table . '.id = articles_comments.article_id');
$commentsCountSql =
$commentsCount->getSqlString($this->getAdapter()->getPlatform());
$sql = new Select();
$sql->from($this->table)
->columns(array('id', 'name', 'text', 'published',
'comments_count' => new Expression('(' . $commentsCountSql .
')')))
->join('admins', $this->table . '.admins_id = admins.id',
array('admin_name' => 'name'), Select::JOIN_LEFT)
->where(array($this->table.'.site_id = ?'=>(int)$site))
->order('published DESC');
return $sql;
}
Hope this helps
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-FrameWork-2-Paginator-tp4657646p4657738.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]