cakephp 中模型的附加属性?

发布于 2024-12-02 09:10:51 字数 177 浏览 8 评论 0原文

我开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴梦长久 2024-12-09 09:10:51

您可以使用 Anh Pham 提供的解决方案,您可以做另一件事,如果只是设置值来显示它们,则在获得结果后将它们添加到控制器中的数组中:

$result['Model']['desired_field_name'] = $static_field;

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:

$result['Model']['desired_field_name'] = $static_field;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文