1
# Sonata\MediaBundle/Resources/config/admin.yml
services:
    sonata.admin.post:
        class: Sonata\MediaBundle\Admin\MediaAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" }
        arguments:
            - ~
            - Sonata\MediaBundle\Entity\Media
            - ~
            - Sonata\MediaBundle\Provider\Pool //??????????????
        calls:
            - [ setTranslationDomain, [Sonata\MediaBundle]]

如果执行此服务,则出现错误:

Catchable Fatal Error: Argument 4 passed to Sonata\MediaBundle\Admin\BaseMediaAdmin::__construct() must be an instance of Sonata\MediaBundle\Provider\Pool, none given, called in C:\server\fs\app\cache\dev\appDevDebugProjectContainer.php on line 1535 and defined in C:\server\fs\vendor\bundles\Sonata\MediaBundle\Admin\BaseMediaAdmin.php line 34

因为 4 参数是字符串而不是对象。

/**
 * @param string                            $code
 * @param string                            $class
 * @param string                            $baseControllerName
 * @param \Sonata\MediaBundle\Provider\Pool $pool
 */
public function __construct($code, $class, $baseControllerName, Pool $pool)
{
    parent::__construct($code, $class, $baseControllerName);

    $this->pool = $pool;
}

我如何通过此服务传递对象?

4

1 回答 1

0

您注入类名而不是服务。尝试注入sonata.media.pool服务作为第四个构造函数参数:

services:
    sonata.admin.post:
        class: Sonata\MediaBundle\Admin\MediaAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" }
        arguments:
            - ~
            - Sonata\MediaBundle\Entity\Media
            - ~
            - @sonata.media.pool
        calls:
            - [ setTranslationDomain, [Sonata\MediaBundle]]
于 2013-09-11T18:06:14.597 回答