Cakephp当某些X不属于Y时如何处理

发布于 2025-01-01 15:11:06 字数 162 浏览 4 评论 0原文

我有一个“单位”表,属于“复杂”。但有些单元实际上是房屋,没有与之相关的综合体。直到现在,我在尝试显示图像时还没有遇到任何问题,因为单位都显示其 UnitsImage 和 ComplexImage。任何房屋都会显示 ComplexImage 未定义的错误(显然)。有没有办法修复关联,或者我是否需要另一个模型?

I have a table of 'units', which belongsTo 'Complex'. But some units are actually houses, which don't have a complex associated with them. I haven't had any problems until now when trying to display images, because units all display their UnitsImage and their ComplexImage. Any houses display an error that ComplexImage not defined (obviously). Is there a way to fix the association or do I need to have another model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

人间☆小暴躁 2025-01-08 15:11:06

根据您提供的信息,我认为不需要在模型中进行任何更改。我认为问题在于您认为存在图像。您是否尝试过在视图中使用 if 语句?

if($house['House']['Complex']['image']){
  echo $this->Html->image($house['House']['Complex']['image']);
}

也许您可以分享您认为的代码?

Based off of the information you have provided I don't believe any changes need to be made within the model. I assume the issue is that in the view you assume an image exists. Have you tried place using an if statement in the view?

if($house['House']['Complex']['image']){
  echo $this->Html->image($house['House']['Complex']['image']);
}

perhaps you could share the code from your view?

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