How to add pagination for component front end (Joo

2019-09-02 20:10发布

问题:

I am new in joomla, i want to know how to add pagination to component for FRONT END, from searching i found only pagination for back end only.

回答1:

So by default there is no pagination in front-end (at least from my knowledge).

It should work like in the backend.

Adding the pagination from the backend in the front-end is not the smoothest thing on earth but this is how it should work:

Your Model should extend JModelList

In the View (view.html.php) you call the Pagination

$this->pagination = $this->get('Pagination');

At the end in the component template (normally default.php) you will just add:

<?php echo $this->pagination->getListFooter(); ?>

For missing CSS classes add the missing files from the administrator side.

Let me know how it works.



回答2:

Thanks Valentin ! For more detail, in the View (view.html.php)

class ProjectViewMyProjects extends JViewLegacy{
protected $items;
protected $pagination;
public function display($tpl=null)
{
$this->items = $this->get('Items');
$this->pagination   = $this->get('Pagination'); 
.............................................
}

At the end in the component template (normally default.php) :

.................[foreach list of db query]...................[endforeach]
$this->pagination->getListFooter();