【问题标题】:Doctrine 2: doctrine:fixtures:load unexpected warning教义 2:教义:固定装置:加载意外警告
【发布时间】:2016-10-12 08:23:31
【问题描述】:

我正在使用 nelmio/alice 包加载 yaml 文件。

在包含多对多关系的第二个实体时会出现奇怪的行为。运行加载命令时会引发警告:

[Symfony\Component\Debug\Exception\ContextErrorException] 警告: 复制(http://lorempixel.com/640/480/?35984):无法打开流: 无法建立连接..

yaml文件代码如下:

AppBundle\Entity\ComponentInstance:
    componentInstance_{1..30}:
      componentCode: <componentInstanceCode()>
      componentId: <numberBetween(1,50)>
      sectionInstance: '@sectionInstance_*'
      date: <datetime()>
      images: '@componentImage_{1..2}'

AppBundle\Entity\ComponentImage:
    componentImage_{1..4}:
      imageName: <name()>
      imagePath: <image()>
      imageAlt: <text()>
      width: <numberBetween(100,500)>
      height: <numberBetween(100,500)>
      components: '@componentInstance_{1..2}'

当我将 cmets 放在 ComponentImage 部分时,它可以正常工作。 整个项目中没有该 url 的踪迹。

image() 函数如下:

public function images()
    {
      $genera = [
          '/images/color_pencils.jpg',
          '/images/half_color_pencils.jpg',
          '/images/rainbow_wood.bmp',
          '/images/color_smoke.jpg'
      ];
      $key = array_rand($genera);
      return $genera[$key];
    }

有什么建议吗?

【问题讨论】:

  • 可能是 ComponentImage 上的一些实体监听器?
  • 可以this 帮忙吗?
  • 谢谢你的 cmets @Matteo 问题是另一个,更愚蠢的方式。我会写一个答案

标签: doctrine-orm fixtures nelmio-alice


【解决方案1】:

问题是由几个元素混合而成的。

我打错字了

imagePath: <image()>

而不是&lt;images()&gt;

第二个也是更令人困惑的一点是&lt;image()&gt; 是nelmio/alice bundle 的保留关键字,它会自动生成一个指向http://lorempixel.com 的url

通过调用正确的函数,它会正确加载数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多