4

我坚持使用nelmio/alice包(富有表现力的固定装置生成器)。我不知道如何将一般config/parameters.yml(在我的情况下为“photoupload_directory”)文件中的参数解析为fixtures.yml.

现在我有这样的硬编码:

photo: <Image('/Users/vivi/projects.2016/cvsymfony.local/storage/uploads/photos',1080,800,false,false)>...

我已经试过了:

photo: <Image(getParameter('photoupload_directory'),1080,800,false,false)>

但这也不起作用。我也试过

$this->getParameter and $this->getContainer()->getParameter%photoupload_directory%符号)。

已经在互联网上搜索过,但到目前为止还没有找到。

4

1 回答 1

0

是的,最后一个解决方案,可能还有更多(用于将参数解析到此类),所以如果您知道,请告诉我。下面为我​​工作..

首先添加命名空间 ContainerAwareInterface :

use Symfony\Component\DependencyInjection\ContainerAwareInterface;

添加特征(在类中):

use \Symfony\Component\DependencyInjection\ContainerAwareTrait;

创建函数:

public function getPhotoUploadDir()
{
    return $this->container->getParameter('photoupload_directory');
}

在fixtures.yml

photo: <Image($this->fake('getPhotoUploadDir'),1080,800,false,false)>
于 2017-08-13T12:16:39.870 回答