# 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;
}
如何使用此服务传递对象?
答案 0 :(得分:0)
您注入了类名而不是服务。尝试注入sonata.media.pool
服务作为第4个构造函数参数:
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]]