CakePHP 哲学问题
所以我有很多不同的模型类型。评论、帖子、评论等。我想将它们加入到一个综合提要中。是否有 CakePHP 风格来合并所有这些数据以供显示,并按时间戳排序?
有很多混乱的方法可以做到这一点,但我想知道是否有一些我缺少的标准方法。谢谢!
So i have a lot of different model types. Comments, posts, reviews, etc. And I want to join them into one integrated feed. Is there a CakePHP style of merging all this data for display, ordered by timestamp?
There are a lot of messy ways to do this but I wonder if there is some standard way which I am missing. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于这些项目来自不同的表,因此在任何情况下都很难从数据库中检索排序在一起的它们。不过,根据数据的组织程度,像这样不混乱的数据应该可以做到:
Since the items are from different tables, it's difficult to retrieve them sorted together from the database in any case. Depending on how well organized your data is though, something as non-messy as this should do:
哲学的?哈哈
不,我认为没有。虽然你可以在 app_model 中编写 afterSave() 。检查您要查找的数据,如果找到,请将其放入缓存中。它可能会很乱,但至少它在一个地方,并且不会对性能产生太大影响。
philosophical? lol
No, I don't think there is one. Although you could write an afterSave() in app_model. Check for the data you're looking for, and if found, put it in Cache. It will probably be messy, but at least it's in one place, and doesn't affect the performance much.
绝对没有办法自动合并数据,但是您可以使用 CakePHP 的 可控制行为。
There's definitely no way to merge the data automatically, but instead of firing separate queries for each relationship, you can grab it all at once using CakePHP's Containable behavior.