0

I trying to install SonataAdmin on my Symfony Project but at the end of the part-2 of the documention when i'm trying to go on "http://localhost:8000/admin/" I have a error : "You have requested a non-existent service "admin.category" in . (which is being imported from "C:\wamp64\www\Sonata/app/config\routing.yml"). Make sure there is a loader supporting the "sonata_admin" type."

I have no idea why, i give give my all my parameters code maybe it's can help you to understand my problem.

parameters: #parameter_name: value

services:

# 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'

`

The indentation is going wrong i add you a picture of this file. Service code

jpp28
  • 61
  • 1
  • 18

3 Answers3

0

I think you did a mistake by writing your category.admin service in: Sonata/app/config/routing.yml, instead of Sonata/src/YourAdminBundle/Resources/config/services.yml

CTR
  • 183
  • 8
  • In my routing.yml there is only : `app: resource: '@AppBundle/Controller/' type: annotation admin_area: resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml" prefix: /admin _sonata_admin: resource: . type: sonata_admin prefix: /admin ` – jpp28 Jun 14 '17 at 13:06
  • Alright I misunderstood which file was matching your code block above, it's services.yml (in app/config) right ? so you should cut your `category.admin` block and paste it in the file i mentioned, that's where you have to declare admin classes – CTR Jun 14 '17 at 13:22
  • Yes it's the app/config/service.yml file. But my project is actually empty. I only have sonata in it i just wanna test it on a empty projet before using it on a real project. I will try to do that on a real project we will see – jpp28 Jun 14 '17 at 13:26
0

The sonata admin services must be public. In your config, you have default as public: false and that is why you get this error.

So you have 2 options:

  1. Specify public: true for your admin service (in your example file)
  2. Or the better way: create a new services file (eg admin.yml) where you dont use these defaults (the _defaults key with public: false). Public is true by default, so you don't have to specify that by _defaults. In this case you must import your new file in config.yml to work:

Top of app/config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: admin.yml }

app/admin.yml content:

services:
    admin.category:
        class: AppBundle\Admin\CategoryAdmin
        arguments: [~, AppBundle\Entity\Category, ~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Category }
slaci
  • 111
  • 4
0

Run this command on terminal. Because You might have missed installing

php composer.phar require sonata-project/doctrine-orm-admin-bundle

After This Add this code below to your AppKernel.php

// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        // set up basic sonata requirements
        // ...
        new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        // ...
    );
}
CodeBugs
  • 23
  • 1
  • 8