cakephp 中模型的附加属性?
我开始使用 cakePhp,我想知道:
当我执行查询时(例如 $this->Product->find(...)),我收到一个数组,对吧?
然后: - 如果我有一些带有默认值的非数据库字段,我必须为每个产品显示这些默认值,我该怎么办?
我看到了虚拟字段,但我无法将静态变量放入其中
I'm starting to use cakePhp and I would like to know:
When I do a query(like with $this->Product->find(...)), I receive an array, right?
Then:
-If I've some non-db fields with default values that I've to display for each product, how do I do?
I saw virtual fields, but I cannot manage to put a static var into it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Anh Pham 提供的解决方案,您可以做另一件事,如果只是设置值来显示它们,则在获得结果后将它们添加到控制器中的数组中:
You can use the solution Anh Pham provided another thing you could do, if it's just setting the values to display them, is add them to the array in your controller after you have the results: