本文整理汇总了PHP中yii\data\ActiveDataProvider::getModels方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::getModels方法的具体用法?PHP ActiveDataProvider::getModels怎么用?PHP ActiveDataProvider::getModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\data\ActiveDataProvider
的用法示例。
在下文中一共展示了ActiveDataProvider::getModels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
*
* @return type
*/
public function run()
{
$data = new ActiveDataProvider(['query' => $this->query, 'pagination' => ['class' => Pagination::class, 'pageSize' => $this->recordOnPage]]);
$data->query->addOrderBy($this->sort);
if (Yii::$app->getRequest()->isAjax) {
Yii::$app->getResponse()->format = Response::FORMAT_JSON;
return $this->controller->renderPartial($this->view, ['model' => $data->getModels()]);
} else {
$this->controller->layout = $this->layout;
return $this->controller->render($this->view, ['model' => $data->getModels(), 'pages' => $data->getPagination()]);
}
}
示例2: run
/**
* @inheritdoc
*/
public function run()
{
$citeProcessor = Yii::createObject('CiteProcessor');
$citeProcessor->init($this->csl, $this->locale);
$references = [];
foreach ($this->dataProvider->getModels() as $model) {
$mapper = new CiteProcMapper($model);
$reference = $mapper->map();
$references[$model->id] = $reference;
}
return $this->render('bibliography', ['widgetId' => $this->getId(), 'references' => $references, 'row' => function ($reference, $mode) use($citeProcessor) {
return $citeProcessor->render($reference, $mode);
}]);
}
示例3: init
/**
* @inheritDoc
*/
public function init()
{
parent::init();
foreach ($this->columns as $key => $column) {
if (is_array($column)) {
$this->columns[$key] = \Yii::createObject(ArrayHelper::merge(['activeDataProvider' => $this->activeDataProvider], $column));
}
}
$this->activeDataProvider->pagination = ['defaultPageSize' => false, 'pageSizeLimit' => false];
$this->reader = \PHPExcel_IOFactory::createReader(\PHPExcel_IOFactory::identify($this->filename));
$this->reader->setReadDataOnly(true);
$this->phpExcel = $this->reader->load($this->filename);
$this->models = ArrayHelper::map($this->activeDataProvider->getModels(), 'primaryKey', function ($item) {
return $item;
});
}
示例4: show
/**
* Returns categories.
* @return Category[]
*/
public function show()
{
$query = self::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->sort->defaultOrder = ['sort' => SORT_ASC, 'id' => SORT_ASC];
return $dataProvider->getModels();
}
示例5: getFromDataProvider
/**
* getFromDataProvider
* @return []Url
*/
private function getFromDataProvider()
{
$remap = $this->remap;
$models = $this->dataProvider->getModels();
$oModels = [];
foreach ($models as $model) {
if ($this->isClosure) {
//function($model)
//return Url
$oModels[] = call_user_func($remap, $model);
} else {
$oModels[] = $this->remapModel($model, $this->remap);
}
}
return $oModels;
}
示例6: actionLeaveAndOvertime
public function actionLeaveAndOvertime()
{
$searchModel = new UserDateSearch();
$dataProvider = $searchModel->searchUser(Yii::$app->request->queryParams, Yii::$app->user->id);
//$dataProvider = Application::find()->where(['user_id'=>Yii::$app->user->id]);
$query = Application::find();
$query->joinWith(['user', 'reasonApplication']);
$query->where(array('application.user_id' => Yii::$app->user->id, 'manager_ok' => 1, 'hrm_ok' => 1));
$query->andWhere('type_id = 1 OR type_id = -1 OR type_id = -11');
$query->orderBy(['from_date' => SORT_DESC]);
$dataProviderUserTimeOver = new ActiveDataProvider(['query' => $query]);
$totalTimeOverWork = 0;
$totalTimeLeaveOfTimeOver = 0;
$totalTimeMoney = 0;
foreach ($dataProviderUserTimeOver->getModels() as $model) {
if ($model->reasonApplication->type_id == 1) {
$totalTimeOverWork += $model->hours_off;
} else {
if ($model->reasonApplication->type_id == -1) {
$totalTimeLeaveOfTimeOver += $model->hours_off;
} else {
if ($model->reasonApplication->type_id == -11) {
$totalTimeMoney += $model->hours_off;
}
}
}
}
return $this->render('leave-and-overtime', ['dataProvider' => $dataProvider, 'dataUserTimeOver' => $dataProviderUserTimeOver, 'totalTimeOverWork' => $totalTimeOverWork, 'totalTimeLeaveOfTimeOver' => $totalTimeLeaveOfTimeOver, 'totalTimeMoney' => $totalTimeMoney, 'totalRemainTime' => $totalTimeOverWork - $totalTimeLeaveOfTimeOver - $totalTimeMoney]);
}
示例7: actionView
public function actionView($id)
{
if ($id <= 0) {
$this->goHome();
}
$allCategory = Category::find()->asArray()->all();
$arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
$arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
/****** 价格筛选 ****/
$result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
$min = $result['min'];
$max = $result['max'];
if ($max > $min && $max > 0) {
// 计算跨度
$priceGrade = 0.0001;
for ($i = -2; $i < log10($max); $i++) {
$priceGrade *= 10;
}
$span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
if ($span == 0) {
$span = $priceGrade;
}
// 计算价格的起点和终点
for ($i = 1; $min > $span * $i; $i++) {
}
for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
}
$priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
for (; $max >= $span * $i; $i++) {
}
$priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
$priceFilter['span'] = $span;
}
/****** 价格筛选 end ****/
/****** 品牌筛选 start ****/
$result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
$ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
$brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
/****** 品牌筛选 end ****/
$query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
// 如果选择了价格区间
if (Yii::$app->request->get('max')) {
$min = intval(Yii::$app->request->get('min'));
$max = intval(Yii::$app->request->get('max'));
if ($min >= 0 && $max) {
$query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
}
}
// 如果选择了品牌
if (Yii::$app->request->get('brand_id')) {
$brandId = intval(Yii::$app->request->get('brand_id'));
if ($brandId >= 0) {
$query->andWhere(['brand_id' => $brandId]);
}
}
// 侧边热销商品
$sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
}
示例8: 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;
}
示例9: 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;
}
示例10: actionIndex
public function actionIndex()
{
$dataProvider = new ActiveDataProvider(['query' => Collection::find()->where(['author_id' => Yii::$app->user->id])]);
$totalCount = $dataProvider->getTotalCount();
$pages = new Pagination(['totalCount' => $totalCount]);
return $this->render('index', ['models' => $dataProvider->getModels(), 'pages' => $pages]);
}
示例11: 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;
}
示例12: actionList
/**
* @return string
*/
public function actionList()
{
$name = Yii::$app->getRequest()->get('name');
$tagModel = '';
if (isset($name)) {
/** @var Tag $tagModel */
$tagModel = Tag::findOne(['name' => $name]);
if (!$tagModel) {
throw new NotFoundHttpException();
}
}
$query = Topic::find()->select('*')->from('topic t')->with('tags', 'firstPostUser', 'lastPostUser');
if (isset($name)) {
$query->innerJoin('tag_topic_assignment tta', 'tta.topic_id = t.id')->where(['tta.tag_name' => $name]);
}
$sort_by = Yii::$app->getRequest()->get('sort_by');
if (!$sort_by || $sort_by == 'new') {
$query->orderBy(['t.last_post_created_at' => SORT_DESC]);
} elseif ($sort_by == 'unanwser') {
$query->andWhere(['t.number_posts' => 0])->orderBy(['t.last_post_created_at' => SORT_DESC]);
} elseif ($sort_by == 'own') {
$id = Yii::$app->getUser()->getId();
$query->andWhere(['t.first_post_user_id' => $id])->orderBy(['t.last_post_created_at' => SORT_DESC]);
}
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => Yii::$app->config->get('display_topics_count')]]);
$topics = $dataProvider->getModels();
return $this->render('list', ['dataProvider' => $dataProvider, 'tagModel' => $tagModel, 'topics' => $topics]);
}
示例13: fillModels
protected function fillModels()
{
$models = $this->dataProvider ? $this->dataProvider->getModels() : $this->query->all();
foreach ($models as $model) {
$this->_models[] = new Model(['instance' => $model, 'standardModel' => $this->_standardModels[0]]);
}
}
示例14: actionList
public function actionList($event_id)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$dp = new ActiveDataProvider();
$dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]);
$dp->pagination->pageSize = 6;
return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()];
}
示例15: writeData
protected function writeData(\PHPExcel_Worksheet $worksheet)
{
foreach ($this->activeDataProvider->getModels() as $row => $model) {
foreach ($this->columns as $col => $column) {
$columnIndex = \PHPExcel_Cell::stringFromColumnIndex($col) . ($row + 2);
switch ($column->format) {
case Column::FormatRaw:
$worksheet->setCellValue($columnIndex, $column->getValue($model));
break;
case Column::FormatUri:
$worksheet->setCellValue($columnIndex, $column->getValue($model));
$worksheet->getCell($columnIndex)->getHyperlink()->setUrl('"' . $column->getValue($model) . '"');
break;
}
}
}
}