感谢您对此的任何帮助. 解决方案 尝试设置 itemCount 在您的 dataProvider:'pagination'=>array('pageSize'=>10,'itemCount'=>$count)或者使用一个新的CPagination对象:$pagination = new CPagination($count);$dataProvider = new CSqlDataProvider($sql, array(//... 其他配置'分页' =>$分页));这是如何工作的:分页的 itemCount 在创建数据提供者期间设置,再次在CSqlDataProvider 的 fetchData 函数: $pagination->setItemCount($this->getTotalItemCount());在创建 data-provider 时只使用传递给 pagination 属性的值,如果我们不传递 itemCount 值,则 的默认值>0 使用.因此,如果我们想访问 offset 或 pageCount 或 currentPage 或 itemCount before调用 fetchData 我们必须显式设置 itemCount.但是,如果我们在调用 fetchData 之后想要这些值,那么由于在 fetchData 中调用了 setItemCount,这些值已经正确填充.一个清晰的例子(在数据提供者创建过程中没有传递itemCount):$dataProvider = NodesTerms::getNodesDataFromTerms($nodeId);$pagination = $dataProvider->getPagination();var_dump($pagination->getPageCount());//这将是零$data=$dataProvider->getData();//getData 调用 fetchData()var_dump($pagination->getPageCount());//现在这将是正确的值I need certain pagination variables in my controller action. such as:1.Current Page Number2.Current Page offset 3.total records displayedi.e. 31 to 40 of 2005 records displayedI 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 itemCount explicitly in your dataProvider:'pagination'=>array( 'pageSize'=>10, 'itemCount'=>$count)Or use a new CPagination object:$pagination = new CPagination($count);$dataProvider = new CSqlDataProvider($sql, array( // ... other config 'pagination' => $pagination));How this works:The pagination's itemCount is set during creation of the data-provider and again in CSqlDataProvider's fetchData function: $pagination->setItemCount($this->getTotalItemCount());During creation of data-provider only the values passed to the pagination property are used, and if we don't pass itemCount value, then the default of 0 is used.So if we want to access offset or pageCount or currentPage or itemCount before the call to fetchData we have to set the itemCount explicitly.However if we want those values after the call to fetchData then the values are already correctly populated due to the call to setItemCount within fetchData.An example for clarity (without passing itemCount during data-provider creation):$dataProvider = NodesTerms::getNodesDataFromTerms($nodeId); $pagination = $dataProvider->getPagination();var_dump($pagination->getPageCount()); // this will be zero$data=$dataProvider->getData(); // getData calls fetchData()var_dump($pagination->getPageCount()); // now this will be correct value 这篇关于来自 DataProvider 的 Yii 分页变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-25 00:47