0

我正在使用 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}'

当我对 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];
    }

有什么建议吗?

4

1 回答 1

1

问题出现是几个元素的混合。

我打错了

imagePath: <image()>

代替<images()>

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

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

于 2016-10-12T08:44:30.907 回答