I need certain pagination variables in my controller action.
such as:
1.Current Page Number
2.Current Page offset
3.total records displayed
i.e. 31 to 40 of 2005 records displayed
I tried the following:
$dataProvider = NodesTerms::getNodesDataFromTerms($nodeId) ;
$pagination = $dataProvider->getPagination();
var_dump($pagination->getPageCount());
//var_dump($pagination->currentPage);
I can get the Pagination Object, but zero (0) in $pagination->currentPage or $pagination->offset etc….
I need this information to dynamically generate meta page title and description on actions with page listings such as pagetitle: page 3 of 10 for American Recipes…
Appreciate any help with this.
Try setting the
itemCountexplicitly in yourdataProvider:Or use a new
CPaginationobject:How this works:
The pagination’s
itemCountis set during creation of the data-provider and again inCSqlDataProvider‘sfetchDatafunction:During creation of data-provider only the values passed to the
paginationproperty are used, and if we don’t passitemCountvalue, then the default of0is used.So if we want to access
offsetorpageCountorcurrentPageoritemCountbefore the call tofetchDatawe have to set theitemCountexplicitly.However if we want those values after the call to
fetchDatathen the values are already correctly populated due to the call tosetItemCountwithinfetchData.An example for clarity (without passing
itemCountduring data-provider creation):