我使用symfony2和sonataadminbundle,sonatamediabundle和sonatacclassification bundle
现在我想为管理面板进行CUSTMIZE设置,但是我有此错误。
[SymfonyComponentConfigExceptionFileLoaderLoadException]
Catchable Fatal Error: Argument 5 passed to SonataMediaBundleAdminBaseMe
diaAdmin::__construct() must implement interface SonataClassificationBundl
eModelCategoryManagerInterface, none given, called in /Users/whitebear/Codin
gWorks/httproot/myapp/app/cache/de_/appDevDebugProjectContaine_.php on l
ine 9494 and defined in . (which is being imported from "/Users/whitebear/Codi
ngWorks/httproot/myapp/app/config/routing.yml").
我所做的是两件事。
制作依赖性文件
application/sonata/mediabundle/depentencyInjection/applicationsOnatamediaextension.php
<?php
namespace ApplicationSonataMediaBundleDependencyInjection;
use SymfonyComponentDependencyInjectionContainerBuilder;
use SymfonyComponentConfigFileLocator;
use SymfonyComponentHttpKernelDependencyInjectionExtension;
use SymfonyComponentDependencyInjectionLoader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ApplicationSonataMediaExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new LoaderYamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
然后为admin提供了服务
application/sonata/mediabundle/resources/config/services.yml
#Disable gallery & media menu from admin panel
services:
sonata.media.admin.media:
class: %sonata.media.admin.media.class%
tags:
- { name: sonata.admin, manager_type: orm, show_in_dashboard: false, label_catalogue: %sonata.media.admin.media.translation_domain% , label_translator_strategy: sonata.admin.label.strategy.underscore }
arguments:
- ~
- %sonata.media.admin.media.entity%
- %sonata.media.admin.media.controller%
- "@sonata.media.pool"
- %sonata.classification.manager.category% # add here.
calls:
- [setModelManager, ["@sonata.media.admin.media.manager"]]
- [setTranslationDomain, [%sonata.media.admin.media.translation_domain%]]
- [setTemplates, [{ inner_list_row: SonataMediaBundle:MediaAdmin:inner_row_media.html.twig , base_list_field: SonataAdminBundle:CRUD:base_list_flat_field.html.twig , list: SonataMediaBundle:MediaAdmin:list.html.twig , edit: SonataMediaBundle:MediaAdmin:edit.html.twig }]]
sonata.media.admin.gallery:
class: %sonata.media.admin.gallery.class%
tags:
- { name: sonata.admin, manager_type: orm, show_in_dashboard: false, label_catalogue: %sonata.media.admin.media.translation_domain% , label_translator_strategy: sonata.admin.label.strategy.underscore }
arguments:
- ~
- %sonata.media.admin.gallery.entity%
- %sonata.media.admin.gallery.controller%
- "@sonata.media.pool"
calls:
- [setTranslationDomain, [%sonata.media.admin.media.translation_domain%]]
- [setTemplates, [{ list: SonataMediaBundle:GalleryAdmin:list.html.twig }]]
sonata MediaBundle admin basemediaadmin
abstract class BaseMediaAdmin extends AbstractAdmin
{
/**
* @var Pool
*/
protected $pool;
/**
* @var CategoryManagerInterface
*/
protected $categoryManager;
/**
* @param string $code
* @param string $class
* @param string $baseControllerName
* @param Pool $pool
* @param CategoryManagerInterface $categoryManager
*/
public function __construct($code, $class, $baseControllerName, Pool $pool, CategoryManagerInterface $categoryManager)
{
parent::__construct($code, $class, $baseControllerName);
$this->pool = $pool;
$this->categoryManager = $categoryManager;
}
感谢@mdma我发现我必须将第5个参数作为基本构造构架的类别managerinterface。
。然后我更新了service.yml,但我有这样的错误。
[SymfonyComponentDependencyInjectionExceptionParameterNotFoundException]
The service "sonata.media.admin.media" has a dependency on a non-existent p
arameter "sonata.classification.manager.category". Did you mean one of thes
e: "sonata.classification.manager.category.class", "sonata.classification.m
anager.tag.class", "sonata.classification.manager.context.class", "sonata.c
lassification.manager.tag.entity", "sonata.classification.manager.category.
entity", "sonata.classification.manager.context.entity", "sonata.classifica
tion.admin.category.class"?
它解决了。我更改了这个句子inservices.yml
- %sonata.classification.manager.category%
to "@sonata.classification.manager.category"
错误说:sonata mediabundle admin baseemediaadmin :: __ construct()
中不存在参数5因此,请查看您的sonata.media.admin.media服务配置中的参数。只有4个参数。您需要添加第五。
在Bundle Config(https://github.com/sonata-project/sonatamediabundle/blob/master/master/resources/config/doctrine_orm_admin.xml)中,有5个参数:
<argument/>
<argument>%sonata.media.admin.media.entity%</argument>
<argument>%sonata.media.admin.media.controller%</argument>
<argument type="service" id="sonata.media.pool"/>
<argument type="service" id="sonata.media.manager.category" on-invalid="null"/>
所以,我认为您可以将 @sonata.media.manager.category添加为第五参数。