SonataAdmin 安装问题
SonataAdmin Install issue
我试图在我的 Symfony 项目上安装 SonataAdmin,但是在文档的第 2 部分末尾,当我试图继续“http://localhost:8000/admin/”时,我遇到了一个错误:"You have requested a non-existent service "admin.category" in .(从 "C:\wamp64\www\Sonata/app/config\routing.yml" 导入)。确保有支持 "sonata_admin" 类型的加载程序。"
我不知道为什么,我给了我所有的参数代码,也许它可以帮助你理解我的问题。
参数:
#parameter_name: 值
服务:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
`
缩进有问题我给你加一张这个文件的图片。 Service code
我认为您将 category.admin
服务写在 Sonata/app/config/routing.yml 中是错误的,
而不是 Sonata/src/YourAdminBundle/Resources/config/services.yml
奏鸣曲管理服务必须 public。在您的配置中,默认值为 public: false
,这就是您收到此错误的原因。
所以你有两个选择:
- 为您的管理服务指定
public: true
(在您的示例文件中)
- 或者更好的方法:创建一个新的服务文件(例如 admin.yml),您不使用这些默认值(
_defaults
键和 public: false
)。 Public 默认为 true
,因此您不必通过 _defaults
指定。在这种情况下,您必须在 config.yml
中导入新文件才能工作:
app/config.yml
的顶部
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: admin.yml }
app/admin.yml
内容:
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
运行 终端上的这个命令。因为您可能错过了安装
php composer.phar require sonata-project/doctrine-orm-admin-bundle
在此之后将下面的代码添加到您的 AppKernel.php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
// set up basic sonata requirements
// ...
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
// ...
);
}
我试图在我的 Symfony 项目上安装 SonataAdmin,但是在文档的第 2 部分末尾,当我试图继续“http://localhost:8000/admin/”时,我遇到了一个错误:"You have requested a non-existent service "admin.category" in .(从 "C:\wamp64\www\Sonata/app/config\routing.yml" 导入)。确保有支持 "sonata_admin" 类型的加载程序。"
我不知道为什么,我给了我所有的参数代码,也许它可以帮助你理解我的问题。
参数: #parameter_name: 值
服务:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
`
缩进有问题我给你加一张这个文件的图片。 Service code
我认为您将 category.admin
服务写在 Sonata/app/config/routing.yml 中是错误的,
而不是 Sonata/src/YourAdminBundle/Resources/config/services.yml
奏鸣曲管理服务必须 public。在您的配置中,默认值为 public: false
,这就是您收到此错误的原因。
所以你有两个选择:
- 为您的管理服务指定
public: true
(在您的示例文件中) - 或者更好的方法:创建一个新的服务文件(例如 admin.yml),您不使用这些默认值(
_defaults
键和public: false
)。 Public 默认为true
,因此您不必通过_defaults
指定。在这种情况下,您必须在config.yml
中导入新文件才能工作:
app/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: admin.yml }
app/admin.yml
内容:
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
运行 终端上的这个命令。因为您可能错过了安装
php composer.phar require sonata-project/doctrine-orm-admin-bundle
在此之后将下面的代码添加到您的 AppKernel.php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
// set up basic sonata requirements
// ...
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
// ...
);
}