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


PHP ActiveDataProvider::getKeys方法代码示例

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


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

示例1: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param bool $unimproved
  *
  * @return ActiveDataProvider
  */
 public function search($params = [], $unimproved = false)
 {
     $query = Release::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params, '');
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'mod_id' => $this->mod_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['<', 'publish_at', $this->publish_at]);
     $query->andFilterWhere(['like', 'version', $this->version]);
     $query->andFilterWhere(['like', 'file_name', $this->version]);
     if ($unimproved) {
         $models = $dataProvider->getModels();
         $keys = $dataProvider->getKeys();
         $unimproved = $this->mod->getUnimprovedReleases($models);
         foreach ($unimproved as $release) {
             array_unshift($models, $release);
             $keys[] = key($models);
         }
         $dataProvider->setModels($models);
         $dataProvider->setKeys($keys);
     }
     return $dataProvider;
 }
开发者ID:devbrom,项目名称:yii2-releases,代码行数:35,代码来源:SearchRelease.php

示例2: getIds

 public function getIds($categoryId, $field)
 {
     if ($field == "categories") {
         //        $this->findAll(array('category_id'=>$categoryId));
         $query = $this->find()->where(['=', 'category_id', $categoryId]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'brand_id']);
         return $provider->getKeys();
     } else {
         return [];
     }
 }
开发者ID:portalsway2,项目名称:APEDevices,代码行数:11,代码来源:Brandcategory.php

示例3: testActiveQuery

 public function testActiveQuery()
 {
     $provider = new ActiveDataProvider(['query' => Customer::find()->orderBy('id ASC')]);
     $models = $provider->getModels();
     $this->assertEquals(10, count($models));
     $this->assertTrue($models[0] instanceof Customer);
     $keys = $provider->getKeys();
     $this->assertTrue($keys[0] instanceof \MongoId);
     $provider = new ActiveDataProvider(['query' => Customer::find(), 'pagination' => ['pageSize' => 5]]);
     $models = $provider->getModels();
     $this->assertEquals(5, count($models));
 }
开发者ID:glcode,项目名称:yii2-2.0.3-annotated,代码行数:12,代码来源:ActiveDataProviderTest.php

示例4: getIds

 public function getIds($Id, $field)
 {
     if ($field == "devices") {
         $query = $this->find()->where(['=', 'device_id', $Id]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'product_id']);
         return $provider->getKeys();
     }
     if ($field == "products") {
         $query = $this->find()->where(['=', 'product_id', $Id]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'device_id']);
         return $provider->getKeys();
     } else {
         return [];
     }
 }
开发者ID:portalsway2,项目名称:APEDevices,代码行数:15,代码来源:Deviceproduct.php

示例5: ajax

 /**
  * @param $headers
  * @throws \yii\base\ExitException
  */
 public function ajax($headers)
 {
     $id_parent = $headers['adm-nestable-id-parent'];
     $items = Yii::$app->getRequest()->post('nestable_items');
     $json['r'] = 0;
     if ($this->tableAlias === null) {
         $query = $this->grid->dataProvider->query;
         if (is_array($query->from)) {
             foreach ($query->from as $k => $table) {
                 if (is_integer($k)) {
                     $this->tableAlias = $table . '.';
                 } else {
                     $this->tableAlias = $k . '.';
                 }
                 break;
             }
         } else {
             if ($query->from) {
                 $this->tableAlias = $query->from . '.';
             }
         }
     } else {
         if ($this->tableAlias = false) {
             $this->tableAlias = '';
         } else {
             $this->tableAlias .= '.';
         }
     }
     if ($id_parent) {
         if ($this->parentCol) {
             $query = $this->getQuery()->where([$this->parentCol => $id_parent]);
             $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => [$this->weightCol => $this->orderBy]]]);
             $models = $dataProvider->getModels();
             $keys = $dataProvider->getKeys();
             $json['r'] = 1;
             $json['items'] = $this->renderItems($models, $keys);
         }
     } elseif (!empty($items)) {
         $weight = [];
         $this->step($weight, $items);
         $json = ['r' => 1, 'weight' => $weight];
     }
     // only need the content enclosed within this widget
     $response = Yii::$app->getResponse();
     $response->clearOutputBuffers();
     $response->setStatusCode(200);
     $response->format = Response::FORMAT_JSON;
     $response->data = $json;
     $response->send();
     Yii::$app->end();
 }
开发者ID:pavlinter,项目名称:yii2-adm,代码行数:55,代码来源:GridNestable.php

示例6: testQuery

 public function testQuery()
 {
     $query = new Query();
     $provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order')->orderBy('id')]);
     $orders = $provider->getModels();
     $this->assertEquals(3, count($orders));
     $this->assertTrue(is_array($orders[0]));
     $this->assertEquals([0, 1, 2], $provider->getKeys());
     $query = new Query();
     $provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order'), 'pagination' => ['pageSize' => 2]]);
     $orders = $provider->getModels();
     $this->assertEquals(2, count($orders));
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:13,代码来源:ActiveDataProviderTest.php


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