我试图实现CakePHP的类似于Facebook上的仪表盘(获得职位,并发布到时间线,而你preSS 看到更多的
它使检索的帖子从previous偏移),但即时通讯仍然困惑的逻辑和工具,我应该使用CakePHP的分页类我实现。
I'm trying to implement a dashboard similar to facebook in cakephp (getting posts and post them to timeline and while you press see more
it keeps retrieving posts from previous offsets) , but im still confused about the logic and tools , should i use the cakephp pagination class in my implementations.
$this->paginate();
它在某种程度上应该通过AJAX accourding一些性能明智的名为
it somehow should be called through ajax accourding to some performance wise
任何帮助或建议从哪里开始呢?
Any helps or suggestions where to start from ?
感谢所有
如果您分页,你是prepending数据的东西 - 你将得到的数据重叠的,这样你问2页 - 并获得年底,就目前的用户来讲,previous页。
If you paginate something that you are prepending data to - you're going to get data overlapping such that you ask for page 2 - and get the end of, as far as the current user is concerned, the previous page.
通常的技术数据源源不断地是使用诸如查询:
The normal technique for an endless stream of data is to use a query like:
SELECT *
FROM foos
WHERE created >= $previousLastTimestamp
ORDER BY created DESC
LIMIT 20
请注意,尽管我使用创建
在这个例子 - 它可以是伪唯一的任何字段
Note that while I'm using created
in this example - it can be any field that is pseudo unique.
当你第一次渲染页面,存储在JavaScript变量的最后一个条目的时间戳,那么你的获取更多内容的逻辑应该是:
When you first render the page, store the timestamp of the last entry in a javascript variable, then your "get more posts" logic should be:
请一个Ajax(获得)的要求,经过最后的时间戳 执行上面的SQL查询(作为 $这个 - > Foo->找到
通话)
在JS更新上一个时间戳,让你知道你在哪里直到下一次用户点击获取更多内容对
Make an ajax (get) request, passing the last timestamp
Perform the above sql query (as a $this->Foo->find
call)
in your js update the last timestamp so that you know where you are up to for the next time the user clicks "get more posts"
之所以使用> =
条件是,除非你要测试领域具有独特的价值,这是有可能存在与价值多行您正在测试。如果你有一个,你是通过(ID)排序天然独特的领域,那么你并不需要使用更大的,或相等,你可以简单地使用大于,避免需要思考重复行。
The reason to use a >=
condition is that, unless the field you are testing against has unique values, it's possible for there to be multiple rows with the value you're testing for. If you have a naturally-unique field that you are sorting by (id) then you don't need to use greater-or-equal, you can simply use greater-than, and avoid needing to think about duplicate rows.
下面的参考其中详细解释了为什么你要处理这样避免了传统系统分页。
Here's a reference which explains in more detail why you should handle systems like this avoiding traditional pagination.