CakePHP:分页,排序,从缓存表中过滤数据 [英] CakePHP: paginating, sorting, filtering data from cached tables
问题描述
您可以假定Cake总是希望数据库结果分页。最简单的解决方案之一是重构类似这样的类到助手中分页)或一个组件(用于过滤),并为您的数据数组提供帮助/组件(有关自定义 helpers 和组件) 。唯一的缺点是,您的应用程序必须在创建分页结果集之前将缓存的数组读入内存。
还有本文,但我不确定是否适用于您的设置。
另一个选择可能是为缓存的数据数组编写自己的数据源,但是Cake的文档在这是一个微薄。我在一些自定义XML订阅源的数据源创建,但从来没有到达添加分页。从第三方数据源浮动我不知道是否甚至可能。
I'm trying to use Cake's native caching methodes to cache some data that I will need to paginate, sort andfiler (search) - that's why I'm caching data arrays, not views or paginated arrays/views. As far as I can see searching/filtering components and Paginator only ask the database, which is what I don't want. Is there any way I could put these together in Cake? Thanks in advance for any answer.
You're correct to assume that Cake always expects a database result to paginate. One of the easiest solutions is refactoring a class like this one into a helper (for the pagination) or a component (for filtering) and feed the helper/component your data arrays (more info on custom helpers and components). The only downside to this is that your application has to read the cached arrays into memory before creating a paginated result set.
There's also this article, but I'm not sure if applies to your setup.
Another option might be to write your own datasource for cached data arrays, but Cake's documentation on this is a little meagre. I've dabbled in the creation of a datasource for some custom XML feeds, but never got around to adding pagination. From the third-party datasources floating around I'm not sure if it's even possible.
这篇关于CakePHP:分页,排序,从缓存表中过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!