CakePHP:分页,排序,从缓存表中过滤数据 [英] CakePHP: paginating, sorting, filtering data from cached tables

查看:151
本文介绍了CakePHP:分页,排序,从缓存表中过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Cake的本地缓存方法来缓存一些数据,我需要分页,排序和filer(搜索) - 这就是为什么我缓存数据数组,而不是视图或分页数组/视图。至于我可以看到搜索/过滤组件和Paginator只询问数据库,这是我不想要的。有什么办法我可以把这些在一起在蛋糕?先感谢任何答案。

解决方案

您可以假定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屋!

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