doctrine-extensions可上传,如何在Zend Framework 2中使用?

时间:2013-11-06 22:56:05

标签: upload doctrine-orm zend-framework2 doctrine-extensions

我在我的项目中集成了doctrine扩展。以时间戳为例。但是如何使用“可上传”行为?

我读了这个doc。他们在usage-part中写了关于使用$listener的内容,但我如何获得此变量?在我的控制器或服务?它来自哪里?

感谢任何建议......

1 个答案:

答案 0 :(得分:1)

最后,得到它......:

代替:

'doctrine' => array(
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'Gedmo\Uploadable\UploadableListener',
                //...
            ),
        ),
    ),
   'driver' => array(
        // ...
    ),
),

使用此功能:通过servicemanager注册可上传的侦听器:

    'doctrine' => array(
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'doctrine_extensions.uploadable',
                //...
            ),
        ),
    ),
   'driver' => array(
        // ...
    ),
),
'service_manager' => array(
    'invokables' => array(
        'doctrine_extensions.uploadable'    => 'Gedmo\Uploadable\UploadableListener'
    )
),

然后在控制器中作为示例,它的工作方式如下:

$uploadManager = $this->getServiceLocator()->get('doctrine_extensions.uploadable');
foreach($this->getRequest()->getFiles()->toArray() as $file) {
    $entity = new MyEntity();
    $uploadManager->addEntityFileInfo($entity, $file);

    // persist($entity) ...
}