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


PHP ActiveDataProvider::prepare方法代码示例

本文整理汇总了PHP中yii\data\ActiveDataProvider::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::prepare方法的具体用法?PHP ActiveDataProvider::prepare怎么用?PHP ActiveDataProvider::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\data\ActiveDataProvider的用法示例。


在下文中一共展示了ActiveDataProvider::prepare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 public function init()
 {
     if (is_array($this->remap)) {
         $this->isClosure = false;
     } elseif (is_callable($this->remap)) {
         $this->isClosure = true;
     } else {
         throw new ErrorException('remap is wrong type!.');
     }
     //init dataProvider
     $this->dataProvider->prepare();
     return parent::init();
 }
开发者ID:advance100,项目名称:yunjianyi,代码行数:13,代码来源:SitemapUrlsetAction.php

示例2: actionIndex

 /**
  * Lists all MyClick models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = (new \yii\db\Query())->select('article.*')->from('my_click')->where(['user_id' => \Yii::$app->user->id])->orderBy('my_click.id DESC');
     $click_query = $query->limit(50)->join('LEFT JOIN', 'article', 'article.id = my_click.article_id');
     $provide = new ActiveDataProvider(['query' => $click_query, 'pagination' => ['pageSize' => 10]]);
     $provide->prepare();
     $pagination = $provide->getPagination();
     return $this->render('index', ['data' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]);
 }
开发者ID:Brother-Simon,项目名称:yii2-starter-kit,代码行数:13,代码来源:MyClickController.php

示例3: actionIndex

 public function actionIndex()
 {
     if (\Yii::$app->user->isGuest) {
         $this->redirect(['user/sign-in/login']);
     }
     $article = (new Query())->from('article')->all();
     $query = Article::find();
     $provide = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC, 'title' => 'simon']]]);
     $provide->prepare();
     $pagination = $provide->getPagination();
     return $this->render('index', ['article' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]);
 }
开发者ID:Brother-Simon,项目名称:yii2-starter-kit,代码行数:12,代码来源:SiteController.php

示例4: actionIndex

 /**
  * Lists all words.
  * @param string $sort
  * @param string $search
  * @return mixed
  */
 public function actionIndex($sort = null, $search = null)
 {
     $query = Word::find()->userId(Yii::$app->user->id);
     if ($search === null) {
         $query->sort($sort);
     } else {
         $query->search($search);
     }
     $provider = new ActiveDataProvider(['query' => $query, 'sort' => false, 'pagination' => ['pageSize' => Yii::$app->params['wordPerPage']]]);
     $provider->prepare(true);
     return $this->render('index', ['provider' => $provider, 'search' => $search]);
 }
开发者ID:highestgoodlikewater,项目名称:yii2-englishwordbook-demo,代码行数:18,代码来源:WordController.php

示例5: search

 public function search($params)
 {
     $query = Url::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => []]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'name', $this->name]);
     $dependency = new \yii\caching\DbDependency(['sql' => 'SELECT MAX(updated_at) FROM url', 'reusable' => true]);
     Yii::$app->db->cache(function ($db) use($dataProvider) {
         $dataProvider->prepare();
     }, Yii::$app->params['cacheExpire'], $dependency);
     return $dataProvider;
 }
开发者ID:nicdnepr,项目名称:skidos,代码行数:16,代码来源:UrlSearch.php

示例6: actionCategory

 /**
 //     * @param integer|null $category
 * @return array - dataProvider and pagination.
 */
 public function actionCategory()
 {
     // controller->action->id: e.g table-lights
     $categoryID = $this->findCategoryBySlug(\Yii::$app->controller->action->id);
     //        $productsQuery = Product::find();
     //        $productsQuery->joinWith('category');
     //        $productsQuery
     //            ->orFilterWhere(['category.parent_id' => $categoryID])
     //            ->orWhere(['category.id' => $categoryID]);
     $productsQuery = Product::find()->joinWith('category')->orFilterWhere(['category.parent_id' => $categoryID])->orWhere(['category.id' => $categoryID]);
     $dataProvider = new ActiveDataProvider(['query' => $productsQuery, 'pagination' => ['pagesize' => 3]]);
     $dependency = new DbDependency();
     $dependency->sql = 'SELECT count(id) FROM product';
     \Yii::$app->db->cache(function ($db) use($dataProvider) {
         $dataProvider->prepare();
     }, 3600, $dependency);
     return $dataProvider;
 }
开发者ID:Krinnerion,项目名称:shop,代码行数:22,代码来源:CatalogController.php

示例7: buildPages

 /**
  * Create sitemap files
  * @return array
  */
 public function buildPages()
 {
     /** @var \yii\db\ActiveRecord $owner */
     $owner = $this->owner;
     $query = $owner::find();
     $basePath = $this->module->getFilesPath();
     preg_match('/([A-Za-z]+)$/', get_class($owner), $matchResult);
     $fileSuffix = strtolower($matchResult[0]);
     // Apply scopes
     if (is_callable($this->scope)) {
         call_user_func($this->scope, $query);
     }
     // Build data provider for separated on pages
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->module->perPage, 'pageSizeLimit' => [10, 50000]]]);
     // Build pages
     $pages = [];
     $dataProvider->prepare();
     $pageCount = $dataProvider->pagination->getPageCount();
     for ($page = 0; $page < $pageCount; $page++) {
         $dataProvider->pagination->setPage($page);
         $dataProvider->prepare(true);
         // Processing one page
         $pageUrls = [];
         $n = 0;
         foreach ($dataProvider->getModels() as $model) {
             $urlData = call_user_func($this->dataClosure, $model);
             $pageUrls[$n]['loc'] = $urlData['loc'];
             $pageUrls[$n]['lastmod'] = $urlData['lastmod'];
             if (isset($urlData['changefreq'])) {
                 $pageUrls[$n]['changefreq'] = $urlData['changefreq'];
             } elseif ($this->defaultChangefreq !== false) {
                 $pageUrls[$n]['changefreq'] = $this->defaultChangefreq;
             }
             if (isset($urlData['priority'])) {
                 $pageUrls[$n]['priority'] = $urlData['priority'];
             } elseif ($this->defaultPriority !== false) {
                 $pageUrls[$n]['priority'] = $this->defaultPriority;
             }
             if (isset($urlData['news'])) {
                 $pageUrls[$n]['news'] = $urlData['news'];
             }
             if (isset($urlData['images'])) {
                 $pageUrls[$n]['images'] = $urlData['images'];
             }
             ++$n;
         }
         $xmlData = Yii::$app->view->renderPhpFile($this->module->viewPath . '/default/page-template.php', ['urls' => $pageUrls]);
         $fileUrl = "sitemap_files/{$fileSuffix}_{$page}.xml";
         if (file_put_contents($basePath . '/' . $fileUrl, $xmlData)) {
             $pages[] = ['loc' => $fileUrl, 'lastmod' => time()];
             echo "OK: {$basePath}/{$fileUrl}\n";
         }
     }
     return $pages;
 }
开发者ID:voskobovich,项目名称:yii2-sitemap-module,代码行数:59,代码来源:SitemapBehavior.php

示例8: init

 /**
  * init
  */
 public function init()
 {
     //init dataProvider
     $this->dataProvider->prepare();
     return parent::init();
 }
开发者ID:teknosuper,项目名称:yii2-sitemap,代码行数:9,代码来源:SitemapUrlsetAction.php

示例9: getDataProvider

 /**
  * @param $params
  * @return ActiveDataProvider
  * @throws \yii\base\InvalidConfigException
  */
 public static function getDataProvider($params)
 {
     $query = Post::find()->with('user', 'topic')->orderBy(['created_at' => SORT_ASC]);
     if ($params['topic_id']) {
         $query->andWhere(['topic_id' => $params['topic_id']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['route' => '/topic/default/view', 'params' => ['id' => $params['topic_id'], 'page' => $params['page']], 'forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => Yii::$app->config->get('display_posts_count')]]);
     $dataProvider->prepare();
     return $dataProvider;
 }
开发者ID:marley-php,项目名称:linuxforum,代码行数:15,代码来源:Post.php

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