如何使用CDataProvider在Yii中创建自己的DataProvider? [英] How to create my own DataProvider in Yii using CDataProvider?

查看:117
本文介绍了如何使用CDataProvider在Yii中创建自己的DataProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于下面这样的情况.我正在使用CSqlDataProvider及其内部使用限制和偏移量的分页(页面大小)来获取一些数据.然后我得到

I am in a situation like this below. I am fetching some data using CSqlDataProvider and its pagination (page size) which internally uses limit and offset. And after that I get

$ rawData = $ sqldp-> getData();

$rawData = $sqldp->getData();

现在,我需要进行一些处理并添加其他数据.现在,我得到

Now I need to do some processing and adding additional data. So now I get

$ modRawData =修改($ rawData);

$modRawData = modification($rawData);

现在,如果我创建一个CArrayDataProvider将其转换为Dataprovider,以便可以使用CListView.

Now If I create one CArrayDataProvider to convert it into a Dataprovider so that I can use the CListView.

但是我的问题在这里.现在我无法进行分页.如果我使用CLinkPager,则可能.但是还有其他方法可以使我创建自己的DATAPROVIDER并在创建dataProvider时处理分页.

But My problem is here. Now I am unable to do Pagination. If I use CLinkPager its possible. But is there any other way so that I can create my own DATAPROVIDER and can handle the pagination while creating the dataProvider.

推荐答案

最后我得到了答案.是的,我可以通过扩展CDataProvider来创建我的自定义DataProvider.但是我只需要实现三个功能

At last I got the answer. And yes I can create my custom DataProvider by extending CDataProvider. But I needed to only implement three functions

fetchData,fetchKeys,calculateTotalItemCount

fetchData, fetchKeys, calculateTotalItemCount

最后,您需要根据需要将自己的逻辑写入fetchData.

And lastly you need to write your own logic into fetchData as you want.

这篇关于如何使用CDataProvider在Yii中创建自己的DataProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆