本文整理汇总了PHP中yii\data\ActiveDataProvider::refresh方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::refresh方法的具体用法?PHP ActiveDataProvider::refresh怎么用?PHP ActiveDataProvider::refresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\data\ActiveDataProvider
的用法示例。
在下文中一共展示了ActiveDataProvider::refresh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPaginationBeforeModels
public function testPaginationBeforeModels()
{
$query = new Query();
$provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order')->orderBy('id')]);
$pagination = $provider->getPagination();
$this->assertEquals(0, $pagination->getPageCount());
$this->assertCount(3, $provider->getModels());
$this->assertEquals(1, $pagination->getPageCount());
$provider->getPagination()->pageSize = 2;
$this->assertEquals(3, count($provider->getModels()));
$provider->refresh();
$this->assertEquals(2, count($provider->getModels()));
}
示例2: exportToFile
/**
* Вывод в файл
* @param ActiveDataProvider $dataProvider
* @param string $sFileName
* @return boolean
*/
public function exportToFile($dataProvider, $sFileName)
{
$dataProvider->prepare();
$nMaxCount = $dataProvider->pagination->totalCount;
$objPHPExcel = new PHPExcel();
$oSheet = $objPHPExcel->getSheet(0);
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
$bCache = PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
$oDefaultStyle = $objPHPExcel->getDefaultStyle();
$oDefaultStyle->getFont()->setName('Arial');
$oDefaultStyle->getFont()->setSize(8);
// $oSheet->getPageSetup()
// ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT) // ORIENTATION_LANDSCAPE
// ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4)
// ->setFitToPage(true)
// ->setFitToWidth(1)
// ->setFitToHeight(0);
//
// $oSheet->getPageMargins()
// ->setTop(0.5)
// ->setRight(0.35)
// ->setLeft(0.35)
// ->setBottom(1);
// $oSheet->getHeaderFooter()
// ->setEvenFooter('&CСтраница &P [&N]')
// ->setOddFooter('&CСтраница &P [&N]');
$nPageCount = $dataProvider->pagination->pageCount;
if ($dataProvider->pagination->totalCount > $nMaxCount) {
$nPageCount = floor($nMaxCount / $dataProvider->pagination->pageSize);
}
$cou = 0;
$nRow = $this->nStartRow;
foreach ($this->columnWidth as $k => $v) {
if ($v !== null) {
$oSheet->getColumnDimension($this->colIndexToName($k + 1))->setWidth($v);
}
}
$sLastCol = $this->colIndexToName(max(count($this->columnWidth), count($this->columnTitles), count($this->columnValues)));
$n = $nRow;
$sTit = 'A' . $nRow++;
$oSheet->setCellValue($sTit, 'Выгрузка от ' . date('d.m.Y H:i'));
$objPHPExcel->getActiveSheet()->mergeCells($sTit . ':' . $sLastCol . $n);
$sdataTitle = $this->dataTitle === null ? Yii::$app->name : $this->dataTitle;
if ($sdataTitle != '') {
$n = $nRow;
$sTit = 'A' . $nRow++;
$oSheet->setCellValue($sTit, $sdataTitle);
$objPHPExcel->getActiveSheet()->mergeCells($sTit . ':' . $sLastCol . $n);
}
if (count($this->columnTitles) > 0) {
$nRow++;
$oSheet->fromArray($this->columnTitles, null, 'A' . $nRow++);
}
for ($page = 0; $page < $nPageCount; $page++) {
$dataProvider->pagination->setPage($page);
$dataProvider->refresh();
foreach ($dataProvider->getModels() as $model) {
$aData = [];
foreach ($this->columnValues as $v) {
$aData[] = $v instanceof Closure ? call_user_func($v, $model, $cou) : $model->{$v};
}
$oSheet->fromArray($aData, null, 'A' . $nRow);
$cou++;
$nRow++;
}
}
$oSheet->getPageSetup()->setPrintArea('A' . $this->nStartRow . ':' . $sLastCol . ($nRow - 1));
$format = $this->getFileExt($sFileName, 'xls');
if ($format == 'xls') {
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
} else {
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
}
$objWriter->save($sFileName);
return true;
}