当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveDataProvider::refresh方法代码示例

本文整理汇总了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()));
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:13,代码来源:ActiveDataProviderTest.php

示例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;
 }
开发者ID:mosedu,项目名称:confprof,代码行数:82,代码来源:ExcelexportBehavior.php


注:本文中的yii\data\ActiveDataProvider::refresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。