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


PHP ActiveDataProvider::setModels方法代码示例

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


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

示例1: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->dataProvider == null && $this->model == null) {
         throw new InvalidConfigException('"dataProvider" or just at least a "model" must be set in bibliography widget.');
     }
     if ($this->model != null) {
         $this->dataProvider = new ActiveDataProvider();
         $this->dataProvider->setModels([$this->model]);
     }
 }
开发者ID:jobrunner,项目名称:yii2-inlitteris,代码行数:14,代码来源:Bibliography.php

示例2: actionSearch

 /**
  * Lists all Applyjobs models.
  * @return mixed
  */
 public function actionSearch()
 {
     $data = Yii::$app->request->post();
     $longitude = $data['longitude'];
     $latitude = $data['latitude'];
     $query = (new \yii\db\Query())->select('daters.*,users.phone,users.nickname,users.thumb,hobbies.hobby')->from('daters')->orderBy(sprintf('abs(daters.longitude - %f) + abs(daters.latitude - %f)', $longitude, $latitude))->join('INNER JOIN', 'users', 'daters.userid = users.id')->join('INNER JOIN', 'hobbies', 'daters.hobbyid = hobbies.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //$this->load($params);
     //$value = 0;
     if (!empty($data)) {
         if (isset($data['phone'])) {
             $query->andFilterWhere(['users.phone' => $data['phone']]);
         }
         if (isset($data['hobbyid'])) {
             $query->andFilterWhere(['hobbyid' => $data['hobbyid']]);
         }
         if (isset($data['content'])) {
             $query->andFilterWhere(['like', 'content', $data['content']]);
         }
     }
     $daters = $dataProvider->getModels();
     //$result = array ();
     //$result ['item'] = array ();
     //$tbreplys = (new \yii\db\Query ())->select('tbreplys.*,users.phone,users.nickname,users.thumb')->orderBy ( "tbreplys.created_at desc" )->join ( 'INNER JOIN', 'users', ' tbmessages.userid =users.id ')->where('tbreplys.messageid in ');
     foreach ($daters as $i => $dater) {
         $info = $dater;
         $info["distance"] = $this->getDistance($latitude, $longitude, $info['latitude'], $info['longitude']);
         $daters[$i] = $info;
     }
     $dataProvider->setModels($daters);
     return $dataProvider;
 }
开发者ID:jiaweizhou,项目名称:alliance,代码行数:36,代码来源:DatersController.php

示例3: 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

示例4: actionSearch

 /**
  * Lists all Applyjobs models.
  * @return mixed
  */
 public function actionSearch()
 {
     $data = Yii::$app->request->post();
     $longitude = $data['longitude'];
     $latitude = $data['latitude'];
     $query = (new \yii\db\Query())->select('applyjobs.*,users.phone,users.nickname,users.thumb,professions.profession')->from('applyjobs')->orderBy(sprintf('abs(applyjobs.longitude - %f) + abs(applyjobs.latitude - %f)', $longitude, $latitude))->join('INNER JOIN', 'users', 'applyjobs.userid = users.id')->join('INNER JOIN', 'professions', 'applyjobs.professionid = professions.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //$this->load($params);
     //$value = 0;
     if (!empty($data)) {
         if (isset($data['phone'])) {
             $query->andFilterWhere(['users.phone' => $data['phone']]);
         }
         if (isset($data['professionid'])) {
             $query->andFilterWhere(['professionid' => $data['professionid']]);
         }
         if (isset($data['jobproperty'])) {
             $query->andFilterWhere(['jobproperty' => $data['jobproperty']]);
         }
         if (isset($data['title'])) {
             $query->andFilterWhere(['like', 'title', $data['title']]);
         }
     }
     $applyjobs = $dataProvider->getModels();
     foreach ($applyjobs as $i => $applyjob) {
         $info = $applyjob;
         $info["distance"] = $this->getDistance($latitude, $longitude, $info['latitude'], $info['longitude']);
         $applyjobs[$i] = $info;
     }
     $dataProvider->setModels($applyjobs);
     return $dataProvider;
 }
开发者ID:jiaweizhou,项目名称:alliance,代码行数:36,代码来源:ApplyjobsController.php

示例5: queryWithConditions

 public function queryWithConditions($conditions)
 {
     $query = (new \yii\db\Query())->select(['area', 'position_name', 'latitude', 'longitude', 'alias'])->from('area_position')->where($conditions);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $models = $dataProvider->getModels();
     // modify models
     $models = $this->foldAreas($models);
     $dataProvider->setModels($models);
     return $dataProvider;
 }
开发者ID:Olwn,项目名称:pm25,代码行数:10,代码来源:AreaPositionController.php

示例6: queryWithConditions

 public function queryWithConditions($conditions)
 {
     $query = (new \yii\db\Query())->select('*')->from('data_mobile');
     if (strlen($conditions['time_point']) < 15) {
         $query->where(['=', "DATE_FORMAT(time_point, '%Y-%m-%d')", $conditions['time_point']]);
         unset($conditions['time_point']);
     }
     $query->andWhere($conditions);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $model = new $this->modelClass();
     $models = $dataProvider->getModels();
     $dataProvider->setModels($models);
     return $dataProvider;
 }
开发者ID:Olwn,项目名称:pm25,代码行数:14,代码来源:MobileDataController.php

示例7: actionIndex

 /**
  * Lists all Assignment models.
  * @return mixed
  */
 public function actionIndex()
 {
     $manager = Yii::$app->getAuthManager();
     $class = $this->module->userClassName;
     $idField = $this->module->idField;
     $usernameField = $this->module->usernameField;
     $items = array_filter(array_merge($manager->getRoles(), $manager->getPermissions()), function ($item) {
         return $item->name[0] !== '/';
     });
     $query = $class::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->andFilterWhere(['like', $this->module->usernameField, Yii::$app->request->get('q', '')]);
     $models = array_map(function ($user) use($manager, $idField, $usernameField, $items) {
         $assignment = [];
         foreach ($manager->getAssignments($user[$idField]) as $item) {
             $assignment[] = $items[$item->roleName];
         }
         ArrayHelper::multisort($assignment, ['type', 'name']);
         return ['id' => $user->{$idField}, 'username' => $user->{$usernameField}, 'assignments' => $assignment];
     }, $dataProvider->getModels());
     $dataProvider->setModels($models);
     return $dataProvider;
 }
开发者ID:Backflag,项目名称:xlzx,代码行数:27,代码来源:AssignmentController.php

示例8: queryWithConditions

 public function queryWithConditions($conditions)
 {
     $query = (new \yii\db\Query())->select('*')->from('air_quality');
     if (!isset($conditions['time_point'])) {
         $sql = "select time_point from air_quality where id=( select MAX(id) from air_quality)";
         //a subquery to get the latest time
         $connection = Yii::$app->db;
         $command = $connection->createCommand($sql);
         $result = $command->queryScalar();
         // get data of latest time
         $query->where(['=', 'time_point', $result]);
     } else {
         if (strlen($conditions['time_point']) < 15) {
             $query->where(['=', "DATE_FORMAT(time_point, '%Y-%m-%d')", $conditions['time_point']]);
         }
         unset($conditions['time_point']);
     }
     $query->andWhere($conditions);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $model = new $this->modelClass();
     $models = $dataProvider->getModels();
     $dataProvider->setModels($models);
     return $dataProvider;
 }
开发者ID:Olwn,项目名称:pm25,代码行数:24,代码来源:AirQualityController.php

示例9: actionGet

 public function actionGet()
 {
     $data = Yii::$app->request->post();
     $user = Users::findOne(['phone' => $data['phone']]);
     // $data = Message::find ()->select ( 'msg.id' )->join ( 'INNER JOIN', 'friends', ' msg.userid =friends.friendid and msg.userid = :id ', [':id' => Yii::$app->user->id ]);
     $query = (new \yii\db\Query())->distinct()->select(['messages.*', 'users.phone', 'users.thumb', 'users.nickname', 'if(isnull(zans.id),0,1) as iszaned', 'if(isnull(collects.id),0,1) as iscollected'])->from('messages')->join('INNER JOIN', 'users', 'messages.userid =users.id')->join('INNER JOIN', 'friends', ' messages.userid =friends.friendid and friends.myid = :id  or messages.userid = :id', [':id' => $user['id']])->join('LEFT JOIN', 'zans', 'zans.messageid = messages.id and zans.userid = :id', [':id' => $user['id']])->join('LEFT JOIN', 'collects', 'collects.messageid = messages.id and collects.userid = :id', [':id' => $user['id']])->orderby('messages.created_at desc');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $messages = $dataProvider->getModels();
     $result = array();
     $result['item'] = array();
     //$tbreplys = (new \yii\db\Query ())->select('tbreplys.*,users.phone,users.nickname,users.thumb')->orderBy ( "tbreplys.created_at desc" )->join ( 'INNER JOIN', 'users', ' tbmessages.userid =users.id ')->where('tbreplys.messageid in ');
     foreach ($messages as $i => $message) {
         $info = $message;
         $info['ismy'] = $info['userid'] == $user['id'] ? 1 : 0;
         $info['replys'] = (new \yii\db\Query())->select(['replys.*', 'user1.nickname as fromnickname', 'user1.phone as fromphone', 'user1.thumb as fromthumb', 'user2.nickname as tonickname', 'user2.phone as tophone', 'user2.thumb as tothumb'])->from('replys')->join('INNER JOIN', 'users user1', 'user1.id = replys.fromid and replys.messageid = :id', [':id' => $message['id']])->join('Left JOIN', 'users user2', 'user2.id = replys.toid')->orderBy("replys.created_at")->limit(20)->all();
         $info['zans'] = (new \yii\db\Query())->select('u.phone,u.nickname')->from('zans z')->join('INNER JOIN', 'users u', 'u.id=z.userid and z.messageid=:id', [':id' => $message['id']])->orderBy('z.created_at desc')->limit(10)->all();
         $messages[$i] = $info;
     }
     $dataProvider->setModels($messages);
     return $dataProvider;
     // return $model;
 }
开发者ID:jiaweizhou,项目名称:alliance,代码行数:22,代码来源:MessagesController.php

示例10: search

 public function search($data, $type)
 {
     if (!(isset($data) && isset($data['phone']) && isset($type))) {
         return array('flag' => 0, 'msg' => 'no enough arg!');
     }
     $user = Users::findOne(['phone' => $data['phone']]);
     $query = (new \yii\db\Query())->select(['tbmessages.*', 'users.phone', 'users.nickname', 'users.thumb', 'if(isnull(concerns.id),0,1) as isconcerned', 'if(isnull(tblikes.id),0,1) as isliked'])->from('tbmessages')->join('INNER JOIN', 'users', 'tbmessages.userid =users.id');
     switch ($type) {
         case 1:
             $query = $query->orderBy("tbmessages.created_at desc")->join('LEFT JOIN', 'concerns', 'tbmessages.userid = concerns.concernid and concerns.myid=:id', [':id' => $user['id']])->join('LEFT JOIN', 'tblikes', 'tblikes.tbmessageid =tbmessages.id and tblikes.userid=:id', [':id' => $user->id]);
             break;
         case 2:
             $query = $query->orderBy("tbmessages.likecount desc")->join('LEFT JOIN', 'concerns', 'tbmessages.userid = concerns.concernid and concerns.myid=:id', [':id' => $user['id']])->join('LEFT JOIN', 'tblikes', 'tblikes.tbmessageid =tbmessages.id and tblikes.userid=:id', [':id' => $user->id]);
             break;
         case 3:
             $query = $query->orderBy("tbmessages.created_at desc")->join('INNER JOIN', 'concerns', 'tbmessages.userid = concerns.concernid and concerns.myid=:id', [':id' => $user['id']])->join('LEFT JOIN', 'tblikes', 'tblikes.tbmessageid =tbmessages.id and tblikes.userid=:id', [':id' => $user->id]);
             break;
         case 4:
             $query = $query->orderBy("tbmessages.created_at desc")->where(['tbmessages.userid' => $user->id])->join('LEFT JOIN', 'concerns', 'tbmessages.userid = concerns.concernid and concerns.myid=:id', [':id' => $user['id']])->join('LEFT JOIN', 'tblikes', 'tblikes.tbmessageid =tbmessages.id and tblikes.userid=:id', [':id' => $user->id]);
             break;
         case 5:
             $query = $query->orderBy("tbmessages.created_at desc")->join('LEFT JOIN', 'concerns', 'tbmessages.userid = concerns.concernid and concerns.myid=:id', [':id' => $user['id']])->join('INNER JOIN', 'tblikes', 'tblikes.tbmessageid =tbmessages.id and tblikes.userid=:id', [':id' => $user->id]);
             break;
     }
     // 		$dataProvider = new \yii\data\Pagination ( [
     // 				'totalCount' => $query->count (),
     // 				'pageSize' => '20'
     // 		] );
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $tbmessages = $dataProvider->getModels();
     //$tbmessages = $query->orderBy ( "tbmessages.created_at desc" )->offset ( $dataProvider->offset )->limit ( $dataProvider->limit )->all ();
     //$models = $data->orderBy ( "msg.created_at desc" )->limit ( $pages->limit )->all ();
     //$models = $data->orderBy ( "msg.created_at desc" )->all ();
     $result = array();
     $result['item'] = array();
     //$tbreplys = (new \yii\db\Query ())->select('tbreplys.*,users.phone,users.nickname,users.thumb')->orderBy ( "tbreplys.created_at desc" )->join ( 'INNER JOIN', 'users', ' tbmessages.userid =users.id ')->where('tbreplys.tbmessageid in ');
     foreach ($tbmessages as $i => $tbmessage) {
         $info = $tbmessage;
         $info['replys'] = (new \yii\db\Query())->select(['tbreplys.*', 'user1.nickname as fromnickname', 'user1.phone as fromphone', 'user1.thumb as fromthumb', 'user2.nickname as tonickname', 'user2.phone as tophone', 'user2.thumb as tothumb'])->from('tbreplys')->join('INNER JOIN', 'users user1', 'user1.id = tbreplys.fromid and tbreplys.tbmessageid = :id', [':id' => $tbmessage['id']])->join('Left JOIN', 'users user2', 'user2.id = tbreplys.toid')->orderBy("tbreplys.created_at")->limit(20)->all();
         $info['likes'] = (new \yii\db\Query())->select('u.phone,u.nickname,u.thumb')->from('tblikes')->join('INNER JOIN', 'users u', 'u.id=tblikes.userid and tblikes.tbmessageid=:id', [':id' => $tbmessage['id']])->orderby('tblikes.created_at desc')->limit(10)->all();
         //$$dataProvider
         $tbmessages[$i] = $info;
         $result['item'][] = $info;
     }
     $dataProvider->setModels($tbmessages);
     // 		$result['_meta'] = array(
     // 			'totalCount'=>$dataProvider->totalCount,
     // 			'pageCount'=>$dataProvider->pageCount,
     // 			'currentPage'=>$dataProvider->page+1,
     // 			'perPage'=>$dataProvider->pageSize,
     // 		);
     return $dataProvider;
     // return $model;
 }
开发者ID:jiaweizhou,项目名称:alliance,代码行数:54,代码来源:TbmessagesController.php


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