本文整理汇总了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]);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}