如何创建“虚拟场”在 CakePHP 版本中1.2
下面只是我的问题的一个可以理解的示例
“我有一个名为“homes”的表,链接到模型“Home”,其中包含字段 id、title、price。
我想创建一个名为“calculated_price”的虚拟字段,该字段基于一些复杂的计算,该计算根据特定记录的搜索条件而因用户而异
。模型“Home”使用
$this->paginate('Home',array('order'=>'calculated_price ASC'));
“
我有一个正在进行的增强项目,该项目使用 Cake 1.2 版,不支持 Cake Ver 1.3 支持的“virtual_field”概念
,因此请提供一个解决方案......
我如何分页& 'order by' 使用 cakephp $this->paginate(); 动态创建的字段
我们如何/可以调整 cake 1.2 以支持 cake 1.3 的虚拟场概念?或者是否有更好的解决方案?
BELOW IS JUST AN UNDERSTANDABLE EXAMPLE TO MY PROBLEM
"I have a table named 'homes' linked to model 'Home' having fields id,title,price.
I want to create a virtual field named 'calculated_price' which is based on some complex calculation which varies for USER TO USER depending on the search conditions for a particular record.
After that I want to paginate the model 'Home' using
$this->paginate('Home',array('order'=>'calculated_price ASC'));
"
I have an ongoing enhancement project which use Cake version 1.2 that do not support 'virtual_field' concept as supported by Cake Ver 1.3
So please provide a solution to this....
How do I paginate & 'order by' a field which created dynamically using cakephp $this->paginate();
How/Can we tweak cake 1.2 to support virtual field concept of cake 1.3 ?OR is there any better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果在运行时为每个可视化进行计算,为什么不直接使用
$this->set('calculated_price'=>calculated_price);
?
If the calculation is made on runtime for each visualization why don't you just use
$this->set('calulated_price'=>calculated_price);
?
唯一的解决方案:
在用户表中创建一个“非虚拟”字段,您可以在其中通过模型回调方法(例如 afterSave())计算价格
The only solution:
Create a "non-virtual" field in the users table, where you calculate the price via model callback methods e.g. afterSave()